app crashed when creating album

The app crashes when creating a new album. This crash did not occur in our own testing, but after publishing it to the app store, it seems that the probability of occurrence is very high.

Replies

How are we supposed to help you with this? What's an album? What code are you running that's causing the crash?

  • PHFetchResult<PHAssetCollection *> *collectionResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[placeholder.localIdentifier] options:nil];

    crash in this line

Add a Comment
__block PHObjectPlaceholder *placeholder = nil;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetCollectionChangeRequest *request = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:title];
    placeholder = request.placeholderForCreatedAssetCollection;
} completionHandler:^(BOOL success, NSError *error) {
    if (resultBlock) {
        PhotoAlbum *resultAlbum = nil;
        if (placeholder) {
            PHFetchResult<PHAssetCollection *> *collectionResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[
                placeholder.localIdentifier
                ] options:nil];
            if (collectionResult.count) {
                resultAlbum = [[PhotoAlbum alloc] initWithPHAssetCollection:[collectionResult firstObject]
                                                                        options:[self assetFilterFetchOptions:self.fetchOption]];
            } else {
                success = NO;
                error = [NSError errorWithDomain:kDomain code:AlbumNoFound userInfo:@{@"error" : [NSString stringWithFormat:@"没有找到标题为%@的相册", title]}];
            }
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            resultBlock(success, error, resultAlbum);
        });
    }
}];

crash in this:

PHFetchResult<PHAssetCollection *> *collectionResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[
                placeholder.localIdentifier
                ] options:nil];
  • DispatchQueue.main.async { guard let album = PhotoLibrary.shared().findAlbum(title) else { // Wink 相册不存在,创建之后保存 MTPhotoLibrary.shared().createAlbum(title) { error, album in } } }

Add a Comment