IOS 10 UIImagePickerController委托未被调用

时间:2016-10-01 10:44:55

标签: ios objective-c

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

·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];
}

有人能看到这个问题吗?

由于

2 个答案:

答案 0 :(得分:1)

如果您使用Xcode8来运行项目,请检查项目的info.plist,确保有一个用于&#34;隐私照片库使用的密钥&#34;。

你的代码是对的,也许问题是info.plist。

答案 1 :(得分:0)

我遇到了类似的问题,事实证明,一旦选择了图像,拾取器就会被垃圾收集,因此代理人没有被调用。

我需要确保在呈现之前对选择器进行了强有力的引用。

一旦完成,它工作正常。