Skip to content

Instantly share code, notes, and snippets.

@ahbou
Last active October 8, 2019 13:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahbou/a4053dcf8f29c8e06797 to your computer and use it in GitHub Desktop.
Save ahbou/a4053dcf8f29c8e06797 to your computer and use it in GitHub Desktop.
Retreive an image from iCoud using PHImageManager
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = NO;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
NSLog(@"%f", progress); //follow progress
};
//This will work
[[PHImageManager defaultManager] requestImageForAsset:myPhAsset targetSize:self.view.frame.size contentMode:PHImageContentModeAspectFill options:options resultHandler:
^(UIImage *image, NSDictionary *info) {
NSLog(@"reponse %@", info);
NSLog(@"got image %f %f", image.size.width, image.size.height);
}];
//This only works if the image was recently fetched and resides on the phone
[[PHImageManager defaultManager] requestImageDataForAsset:myPhAsset options:options resultHandler:
^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
NSLog(@"reponse %@", info);
UIImage *image = [UIImage imageWithData:imageData scale:1];
NSLog(@"got image %f %f", image.size.width, image.size.height);
}];
@jiehu5114
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment