I have a probabilistic crash in my app, detailed as follows,
0 CoreFoundation ___exceptionPreprocess + 228
1 libobjc.A.dylib objc_exception_throw + 56
2 Photos -[PHPhotoLibrary recordInsertRequest:]
3 Photos -[PHChangeRequestHelper initWithUUID:objectID:changeRequest:] + 136
4 Photos -[PHAssetCollectionChangeRequest initWithUUID:objectID:] + 140
5 Photos +[PHAssetCollectionChangeRequest _changeRequestForAssetCollection:optionalAssets:] + 180
and my code detailed as follows,
__block NSString *localIdentifier = nil;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollectionChangeRequest *collectionRequest = nil;
PHFetchResult <PHAssetCollection *>*result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
for (PHAssetCollection *assetCollection in result) {
if ([assetCollection.localizedTitle isEqualToString:albumName]) {
if ([assetCollection canPerformEditOperation:PHCollectionEditOperationCreateContent]) {
collectionRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
break;
}
}
}
} completionHandler:^(BOOL success, NSError * _Nullable error) {
}];
before run this code, i have the strict logical control to get album permission, and i have followed the api advice,
// if the asset collection does not allow the type of change requested, these methods will raise an exception, call canPerformEditOperation: on the asset collection to determine if the type of edit operation is allowed.
but it is does not work, and the crash are still happened, and https://forums.developer.apple.com/message/155809#155809
is not what i wanted.
Does anyone have the same problems? i really appreciate any help…