PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite];
if (authorizationStatus != PHAuthorizationStatusAuthorized) {
return;
}
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title == %@", "MyAlbum"];
PHFetchResult *collections = [PHAssetCollection fetchAssetCollectionsWithType: PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:fetchOptions];
The above code crashed when fetchAssetCollectionsWithType is called on iOS 17, and the error is “Access to the photo library is not allowed until the photo library is obtainable.”
What’s wrong with my code?
I thought the reason is that I called the function too early, because the system printed the log, “Error returned from daemon: Error Domain=com.apple.accounts Code=7 “(null)” when I called the function before the UIViewController#viewDidLoad is called on my own device which is iOS 17.0.2.
So I called the function after UIViewController#viewDidLoad is called, and I got the above error, “Access to the photo library is not allowed until the photo library is obtainable”