My app uses Apple's UIImagePickerController
to obtain images from photo library. On some iOS 12 phones, an empty image picker is displayed, with the message "No photos or videos". The problem is that there are photos in the phone's library.
Taking a new picture and saving it, outside of the app, clears up the issue; once this is done, the app can pick from the photo library as normal.
Here is the block that is passed to the UIAlertController
(an action sheet asking whether to pick from the camera, or the library):
void (^chooseExistingAction)(void) = ^() {
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
};
Here is the method that presents the image picker:
- (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];
}
}
And, finally, here are the relevant keys from the app's Info.plist
(the values have been slightly redacted):
<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>
Any ideas? I am flummoxed!
Thanks in advance.
I don't see cheking auth status. Take a look for this two ways to check status befor presenting picker and request auth if needed.
First (stole from this answer):
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusAuthorized) {
// do your logic
} else if(authStatus == AVAuthorizationStatusDenied){
// denied
} else if(authStatus == AVAuthorizationStatusRestricted){
// restricted, normally won't happen
} else if(authStatus == AVAuthorizationStatusNotDetermined){
// not determined?!
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", mediaType);
} else {
NSLog(@"Not granted access to %@", mediaType);
}
}];
} else {
// impossible, unknown authorization status
}
Second (stole from this answer):
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized) {
// Access has been granted.
} else if (status == PHAuthorizationStatusDenied) {
// Access has been denied.
} else if (status == PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// Access has been granted.
} else {
// Access has been denied.
}
}];
} else if (status == PHAuthorizationStatusRestricted) {
// Restricted access - normally won't happen.
}