I'm occasionaly seeing requestImageDataForAsset return nil for imageData and no error in the info dict. I have also noticed that when this happens there's a little icon in the Photos app (You'll also note how bllurry the photo is). Sometimes tapping this icon helps. I'd sure like to know what tapping the icon does and what other folks are doing.
@implementation PHAsset (ImageIOBits)
-(void) writeAssetToPath:(NSString*)path completion:(PHAssetWrite)completion
{
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = NO;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{
[ECPActivityIndicator displayActivity:NSLocalizedString(@"iCloud Photo",@"progress indicator") withProgress:progress];
});
};
[[PHImageManager defaultManager] requestImageDataForAsset:self options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
BOOL success = NO;
if(imageData){
if(![ECPActivityIndicator isHidden])
[ECPActivityIndicator displayCompleted:NSLocalizedString(@"Download Complete", @"progress indicator")];
success = [imageData writeToFile:path atomically:YES];
}else{
if(![ECPActivityIndicator isHidden])
[ECPActivityIndicator displayCompleted:NSLocalizedString(@"Trouble Retreiving Photo", @"progress indicator")];
if (info[PHImageErrorKey]) {
NSError* err = info[PHImageErrorKey];
err = err.userInfo[NSUnderlyingErrorKey] ? err.userInfo[NSUnderlyingErrorKey] : err;
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Uh oh", @"Alert title Unexpected results")
message:[NSString localizedStringWithFormat:NSLocalizedString(@"The photo could not be opened. - %@",
@"Alert message - param is name of some error."),
[err localizedDescription]]
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", @"Alert Button saying continue accept or acknowlege.")
otherButtonTitles: nil] show];
}
}
completion(success);
}];
}
@end