【发布时间】:2019-08-31 01:01:45
【问题描述】:
我的应用程序使用 Apple 的 UIImagePickerController 从照片库中获取图像。在某些 iOS 12 手机上,会显示一个空的图像选择器,并显示消息“没有照片或视频”。问题是手机图库里有照片。
在应用程序之外拍摄一张新照片并保存它可以解决问题;完成此操作后,该应用可以照常从照片库中进行选择。
这是传递给UIAlertController 的块(询问是从相机还是从库中选择的操作表):
void (^chooseExistingAction)(void) = ^() {
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
};
这是呈现图像选择器的方法:
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType {
if (![UIImagePickerController isSourceTypeAvailable:sourceType]) {
[self showAlertWithMessage:ImageSourceNotAvailableAlert];
} else {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = sourceType;
imagePicker.delegate = self;
imagePicker.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
[self presentViewController:imagePicker animated:YES completion:NULL];
}
}
最后,这里是来自应用程序Info.plist 的相关键(值已被略微编辑):
<key>NSCameraUsageDescription</key>
<string>This information will be used to provide visual details about [etc]</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This information will be used to provide visual details about [etc]</string>
有什么想法吗?我一脸懵逼!
提前致谢。
【问题讨论】:
标签: ios objective-c uiimagepickercontroller