Allocate self.assetArray
after the nil
assignment or write [self.assetArray removeAllObjects]
instead of assigning it to nil
.
- (void) refreshPhotos {
self.assetArray = nil;
self.assetArray = [[NSMutableArray alloc] init];
//or remove the top 2 lines and try `[self.assetArray removeAllObjects]`
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^(void){
[self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if(group){
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [group numberOfAssets])] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *shouldStop) {
if(result){
if([[result valueForProperty:@"ALAssetPropertyType"] isEqualToString:@"ALAssetTypePhoto"]){
[self.assetArray addObject:result];
}
}
}];
}
} failureBlock:^(NSError *error) {
DebugLog(@"error >>> %@",[error description]);
}];
});
}
also some times i am not receiving the ALAssetLibraryUpdatedAssetsKey in the userInfo of notification,
there are four keys used to get values from the user information dictionary of the ALAssetsLibraryChangedNotification
notification.
NSString * const ALAssetLibraryUpdatedAssetsKey;
NSString * const ALAssetLibraryInsertedAssetGroupsKey;
NSString * const ALAssetLibraryUpdatedAssetGroupsKey;
NSString * const ALAssetLibraryDeletedAssetGroupsKey;