I have an array of list ALAsset URL. I want to convert that URL into an ALAsset one by one and add it into a new array.
Here is my code:
-(void)retrieveAssetsWithArray:(NSArray *)assetsArray
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Background work
__block NSMutableArray *retrievedAssetsArray = [[NSMutableArray alloc] init];
for (int i = 0; i < [assetsArray count]; i++)
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:[NSURL URLWithString:[assetsArray objectAtIndex:i]]
resultBlock:^(ALAsset *asset)
{
if (asset)
{
NSLog(@"assetss: %@", asset);
[retrievedAssetsArray addObject:asset];
NSLog(@"assets arayyyy: %@", retrievedAssetsArray);
}
}
failureBlock:^(NSError *error)
{
NSLog(@"Error: Cannot load asset - %@", [error localizedDescription]);
}
];
}
dispatch_async(dispatch_get_main_queue(), ^{
// Update UI
if ([self.delegate respondsToSelector:@selector(getRetrievedAssetsFromPhotoLibrary:)])
{
NSLog(@"retrievedAssetsArray :%@", retrievedAssetsArray);
[self.delegate getRetrievedAssetsFromPhotoLibrary:retrievedAssetsArray];
}
});
});
}
The part to convert URL to ALAsset is working fine. But the retrievedAssetsArray returns like this when I try logging it in the dispatch_async(dispatch_get_main_queue():
retrievedAssetsArray :(
"ALAsset - Type:Unknown, URLs:(null)",
"ALAsset - Type:Unknown, URLs:(null)",
"ALAsset - Type:Unknown, URLs:(null)",
"ALAsset - Type:Unknown, URLs:(null)"
)
Why is this happening? Can anyone please tell me how I can fix this? Cheers.
getRetrievedAssetsFromPhotoLibrary.