Last active
October 8, 2019 13:32
-
-
Save ahbou/a4053dcf8f29c8e06797 to your computer and use it in GitHub Desktop.
Retreive an image from iCoud using PHImageManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice