nek023/QBImagePicker

iOS 13 First time Blank screen is displayed when user access to photos.

tirupathiAmz opened this issue · 2 comments

IOS-13 Blank screen is displayed when user access to photos is provided and allowed from popup, user need to click again and click on upload from library, then photos will be displayed.

I have the same problem. It's probably because the PHFetchResult handling in iOS 13 is different than before. It's not a complete solution, but I did the following trick:

When the user chooses to allow access to the photo for the first time, it will use the 'photoLibraryDidChange' method in QBAlbumsViewController.m. In iOS 13, tableview reloading does not work properly, so it must be processed separately.

The code is shown below.

-(void)photoLibraryDidChange:(PHChange *)changeInstance
{
dispatch_async(dispatch_get_main_queue(), ^{
// Update fetch results
if (@available(iOS 13.0, *)) {
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
self.fetchResults = @[smartAlbums, userAlbums];
[self updateAssetCollections];
[self.tableView reloadData];
return;
}

    NSMutableArray *fetchResults = [self.fetchResults mutableCopy];
    
    [self.fetchResults enumerateObjectsUsingBlock:^(PHFetchResult *fetchResult, NSUInteger index, BOOL *stop) {
        PHFetchResultChangeDetails *changeDetails = [changeInstance changeDetailsForFetchResult:fetchResult];
        
        if (changeDetails) {
            [fetchResults replaceObjectAtIndex:index withObject:changeDetails.fetchResultAfterChanges];
        }
    }];
    
    if (![self.fetchResults isEqualToArray:fetchResults]) {
        self.fetchResults = fetchResults;

        // Reload albums
        [self updateAssetCollections];
        [self.tableView reloadData];
    }
});

}

I hope this helps. :)

Thank you @jiwoonjo, I changed the code as you mentioned. now It's working fine.