I want to read the specified file (photo from the camera) asynchronously, but for me this does not work.
The variable tempData
gets nil
until I change the requestOptionForPhotos.synchronous
configuration to YES
, then everything will be fine, but I do not want to execute this code synchronously.
Is it possible that I block access to the photo by requesting the same file in another thread? I'm new to objective-c programming and iOS, and I don't know how this 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; }]; }
source share