【发布时间】:2014-04-23 01:58:33
【问题描述】:
我正在尝试使用 UIImagePickerController 从 iPhone 照片库中挑选一个视频,以便我可以将其上传到服务器。 我可以使用 UIImagePickerController 选择图像而不会出现任何错误/崩溃,但是在选择时(不是实际单击选择按钮,而是从库中选择一个视频)视频我的应用程序崩溃了。 它只是在控制台上打印以下行:
设置电影路径:(null)
设置影片路径:/Users/Mahesh/Library/Application Support/iPhone 模拟器/6.1/Media/DCIM/100APPLE/IMG_0006.mp4
事件委托方法 didFinishPickingMediaWithInfo 在调用之前没有被调用,我的应用程序崩溃了。我只是无法弄清楚究竟是什么导致了问题。
以下是我打开 iPhone 库的代码:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//imagePicker.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
[self presentViewController:imagePicker animated:YES completion:nil];
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
UIImage *editedImage = (UIImage *)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Compressing the image size
CGSize newSize = CGSizeMake(400, 400);
UIGraphicsBeginImageContext(newSize);
[editedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(newImage,0.2);//PNGRepresentation(imgView.image);
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
请帮帮我.. 谢谢!
【问题讨论】:
-
我在 iOS 6.1 上遇到了同样的问题,但代码在 iOS7 上仍然运行良好。
-
您使用的是仿真器还是实际设备?我认为您的代码可以在设备上运行,但会在模拟器上崩溃。
标签: ios iphone objective-c xcode5 uiimagepickercontroller