从IPhone项目转ipad的时候,调取系统相册,无效果,控制台打印:
Attempt to present <UIImagePickerController: 0x1209bb800> on <InputInsurancePlicyVC: 0x120972a00> while a presentation is in progress!
解决方案:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[viewController presentViewController:imagePickerVC animated:YES completion:^(){}];
}];
网上找的答案:
https://www.jianshu.com/p/1228a2c910bb
后来我自己也去试了,发现使用:
dispatch_async(dispatch_get_main_queue(), ^{
});
使用gcd也行,先开始我试觉得难道是因为没放到主线程去执行,所以我打印了线程号,发现都是主线程,
所以解决问题的重点可能在异步上,所以:
dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@"当前线程2------%@",[NSThread currentThread]);
[viewController presentViewController:imagePickerVC animated:YES completion:^(){}];
});
然后就可以正常打开相册了,
所以我的猜想是,从 UIAlertController作为控制器,去打开UIimagePickerVC的时候,线程发生了阻塞,为啥发生阻塞,
我不知道。。。。?可能真如那个大佬所言,是alertview销毁的同时,打开了UIimagePickerVC。
解决方案最好还是主线程下异步执行吧,保险。