IOS 10 UIImagePickerController 委托(delegate)未被调用

标签 ios objective-c

我已经设置了以下设置以在使用 iPad 时选择图像。问题是委托(delegate)似乎永远不会被调用。我已经放置了断点,但它们从未被激活。

.H

@interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

.M

- (IBAction)loadImage:(id)sender {

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.delegate = self;

[self presentViewController:self.imagePickerController animated:YES completion:nil];

}

// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

//You can retrieve the actual UIImage
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//Or you can get the image url from AssetsLibrary
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];

[picker dismissViewControllerAnimated:YES completion:nil];
}

任何人都可以看到这个问题吗?

谢谢

最佳答案

如果你使用Xcode8运行项目,请检查项目的info.plist,确保有“Privacy Photo library usage”的 key 。

你的代码是对的,可能是info.plist的问题。

关于IOS 10 UIImagePickerController 委托(delegate)未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39805662/

相关文章:

objective-c - iOS:如何为 iOS 应用渲染 flash?

ios - 当我将UIImage设置为带有URL的NSData时,加载需要一段时间。

ios - Objective-C 内存管理问题

ios - iOS 中 ArcGIS Maps 中的当前位置问题

iphone - 如何确定平移手势的真实最终速度?

ios - 如何在单击时从一个 ViewController(包含自定义 UIView)移动到另一个 ViewController(包含 UITableView)?

ios - 为 iOS 应用程序进行 UX 的最佳且最简单的方法

objective-c - 标签不会出现在 Mac Retina 设备中

objective-c - 更好的性能设置 backgroundView : willDisplayCell or init?

ios - 从数组循环时将标签分配给 UIButton