PHPhotoLibrary performChanges says success but album can't be found

We are trying to create a new photo album using PHPhotoLibrary perform changes with completion handler method:

__block PHObjectPlaceholder* theAlbumPlaceholder;

[ theLibrary performChanges: ^

{

NSString* theAlbumName = [ self getAlbumName ];

PHAssetCollectionChangeRequest* theRequest = [ PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle: theAlbumName ];

theAlbumPlaceholder = theRequest.placeholderForCreatedAssetCollection;

} completionHandler ...


Inside the completion handler, "success" is YES and theAlbumPlaceholder.localIdentifier is not nil. We then call [ PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers: @[ theAlbumPlaceholder.localIdentifier ] options: nil ] but it returns 0 results. How is this possible? It only ever happens in the wild to users, our data shows it only happens on iOS 12. We cannot seem to reproduce in house.


Any ideas why the perform changes would say success YES, but then be unable to find the album you created using the identifier of the placeholder?

Replies

This continues to happen and we continue to have no clue why we can't find the album that is created (even though it is there). Please, please, please help.

Still continues to happen. Is there a way to escalate this to an official bug report?

- (void)createAlbum
{
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"AlbumName"];
    }
                                      completionHandler:^(BOOL success, NSError *error) {
                                          if (success) {        
                                              self.assetCollection = [self getAlbum];
                                          }
                                          if (error) {
                                              NSLog(@"error");
                                          }
                                      }];
}

- (PHAssetCollection *)getAlbum
{
    PHFetchResult *topLevelUserCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];

    for (PHAssetCollection *collection in topLevelUserCollections) {
        if ([collection.localizedTitle isEqualToString:@"AlbumName"]) {
            return collection;
        }
    }
    return nil;
}


Why don't you try the code like above.


I have the same problem as you wrote. But I think the code also can create album.

We got similar problem only for iOS 12 when saving photos to album, the code works well on other system version. CompletionHandler return success but photos cant be found in album.


Many of our users have encountered this problem, and they thought it was our app's bug. We tested it repeatedly but it just performed correctly, so we still can't find the reason and solution.


It is a very important problem for us cause our app is for photography 😟. Please help us.