I want to read specified file (photo from camera roll) asynchronous, but it does not work for me.
Variable tempData gets nil untill I change config requestOptionForPhotos.synchronous to YES, then everything is ok, but I don't want to perform this code synchronous.
Is it possible that I'm blocking access to photo by requesting to the same file in other thread? I'm newbie in objective-c and iOS programming and I don't know how does it works.
NSURL *assetUrl = [[NSURL alloc] initWithString:filepath];
PHFetchResult *collection = [PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:assetUrl] options:nil];
PHImageRequestOptions *requestOptionForPhotos = [[PHImageRequestOptions alloc] init];
requestOptionForPhotos.networkAccessAllowed = YES;
requestOptionForPhotos.synchronous = NO;
__block BOOL isFinished = NO;
__block NSData * tempData = nil;
for(PHAsset *asset in collection) {
[[PHImageManager defaultManager]
requestImageForAsset:asset
targetSize:CGSizeMake(80, 80)
contentMode:PHImageContentModeAspectFill
options:requestOptionForPhotos
resultHandler:^(UIImage *result, NSDictionary *info) {
tempData = UIImagePNGRepresentation(result);
isFinished = YES;
}];
}