I have a strange issue about getting UIImages with PHImageManager.
Everything works fine with when the requested UIImage is not edited from photos app of iPhone;
[[PHImageManager defaultManager] requestImageForAsset:[assets objectAtIndex:0] targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:requestOptions resultHandler:^void(UIImage *image, NSDictionary *info)
{
DebugLog(@"%ld", assets.count);
@autoreleasepool
{
if (image)
{
// Write image to system
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fileName = [NSString stringWithFormat:@"%ld_%@.jpg", (long)assets.count, [NSDate date]];
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
[UIImageJPEGRepresentation(image, 0.5) writeToFile:filePath atomically:YES];
}
}];
But in case that if a user edited the photo from iPhone's self photo editor (i.e. s/he cropped the picture) the PHImageManager fails to retrieve that photo.
Without editing, the dictionary provided in the resultHandler is normal which is called "info":
{
PHImageFileOrientationKey = 0;
PHImageFileSandboxExtensionTokenKey = "5565e83d376d8c4e018b8ea41401e58e5aabbc18;00000000;00000000;000000000000001a;com.apple.app-sandbox.read;00000001;01000003;000000000039a762;/private/var/mobile/Media/DCIM/113APPLE/IMG_3433.PNG";
PHImageFileURLKey = "file:///var/mobile/Media/DCIM/113APPLE/IMG_3433.PNG";
PHImageFileUTIKey = "public.png";
PHImageResultDeliveredImageFormatKey = 9999;
PHImageResultIsDegradedKey = 0;
PHImageResultIsInCloudKey = 0;
PHImageResultIsPlaceholderKey = 0;
PHImageResultOptimizedForSharing = 0;
PHImageResultRequestIDKey = 55;
PHImageResultWantedImageFormatKey = 9999;
}
But after editing from photo application the dictionary becomes:
{
PHImageFileOrientationKey = 0;
PHImageResultDeliveredImageFormatKey = 4031;
PHImageResultIsDegradedKey = 1;
PHImageResultRequestIDKey = 56;
PHImageResultWantedImageFormatKey = 9998;
}
Does anyone faced with this issue before?
Thank you for your replies.
Okey I find out what happens there.
In PHImageRequestOptions there is an option to choose the unadjusted version of the photo by adding;
requestOptions.version = PHImageRequestOptionsVersionUnadjusted;
With this, I successfully get the Image (however in unadjusted format).
Anyone could find further solution without taking the image adjusted, please comment me.
Cheers.