objective-c - 上传视频时iOS 4.3崩溃

标签 objective-c ios ios5 ios4

我有一个iPhone应用程序,可以使用ASIHTTPRequest将图像和视频上传到Web服务。一切在运行iOS 5的设备上都运行良好,但从UIImagePickerController返回后,在4.3及以下版本的设备上崩溃。视频由选择器压缩,然后应用崩溃。下面是-(void)imagePickerController:didFinishPickingMediaWithInfo:方法的代码,以及将视频发布到服务器的方法的代码,以及从视频捕获图像以用作缩略图的方法的代码。关于什么原因导致4.3崩溃?

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

self.mediaType = [info objectForKey:UIImagePickerControllerMediaType];

 if ([self.mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

    // Get asset to use for orientation determination   
    AVAsset *myAsset = [AVAsset assetWithURL:videoURL];

    self.videoOrientation = [self UIInterfaceOrientationToString:[self orientationForTrack:myAsset]];

    UIImage *videoThumbnail = [self getVideoThumbnailFromAVAsset:myAsset];
    self.photoImageView.image = videoThumbnail;

    self.videoData = [[NSMutableData alloc]initWithContentsOfURL:videoURL];
}
[self dismissModalViewControllerAnimated:YES]; 
}

-(UIImage*)getVideoThumbnailFromAVAsset:(AVAsset *)myAsset {
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:myAsset];

Float64 durationSeconds = CMTimeGetSeconds([myAsset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
NSError *error = nil;
CMTime actualTime;
UIImage *myImage;

CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];

if (halfWayImage != NULL) {
    myImage = [UIImage imageWithCGImage:halfWayImage];
    CGImageRelease(halfWayImage);
}
return myImage;
}

- (void)postMessage:(id)sender {

self.uploadButton.enabled = NO;
[self.descriptionTextField resignFirstResponder];
[self.titleTextField resignFirstResponder];

NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSString *sessionKey = [settings stringForKey: @"sessionKey"];

// build URL for request
NSString *baseURL;
NSString *endPoint;

// code here that creates the url component strings baseURL and endPoint

NSString *fullURL = [NSString stringWithFormat:@"%@%@", baseURL, endPoint];
NSURL *url = [NSURL URLWithString:fullURL];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.postFormat = ASIMultipartFormDataPostFormat;

NSString *teamIDStr = [NSString stringWithFormat:@"%d",[self.teamID intValue]];

[request setPostValue:sessionKey forKey:@"sessionKey"];
[request setPostValue:teamIDStr forKey:@"TeamID"];   
[request setPostValue:titleTextField.text forKey:@"lessonName"];
[request setPostValue:descriptionTextField.text forKey:@"lessonDesc"];
[request setPostValue:self.videoOrientation forKey:@"videoOrientation"];

//create video file name
NSDate *date1=[NSDate date];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:@"hhmm"];
NSString *valuestr = [formatter1 stringFromDate:date1];
NSString *moviename = [NSString stringWithFormat:@"video_%@.mov", valuestr];

[request setData:self.videoData withFileName:moviename andContentType:@"video/quicktime" forKey:@"file1.mov"];

[request setUploadProgressDelegate:self.progressBar];
[request setShowAccurateProgress:YES];
self.progressBar.hidden = NO;
[request setDelegate:self];
[request setTimeOutSeconds:600];
[request startAsynchronous];

}

最佳答案

该问题的简单答案:AVAsset类方法

+ (id)assetWithURL:(NSURL *)URL

在iOS 5.0之前不可用。您必须使用具体的子类AVURLAsset使用其类方法为iOS 4.0和4.3实例化AVAsset。
+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options

关于objective-c - 上传视频时iOS 4.3崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9383928/

相关文章:

ios - 在 TTTAttributedLabel 中指定多个/条件链接颜色

ios - Xcode 特征 View 不为零

ios - 使 UIScrollView 可访问其他类

ios - 有谁能帮我向应用商店提交申请吗?

ios - UIWebView无法加载本地网页

iphone - 如何在特定时间发送短信

ios - 如何在 iOS info.plist 文件中本地化字符串数组

ios - xcode swift 如何调试应用程序关闭后崩溃的原因

objective-c - 我可以混合 didSelectRowAtIndexPath : of UITableViewDelegate?

iphone - iOS 4.* 中的方法 isBeingPresented