Created
September 12, 2012 20:50
-
-
Save kleneway/3709815 to your computer and use it in GitHub Desktop.
My implementation of FPPickerController didFinishPickingMediaWithInfo
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
-(void)FPPickerController:(FPPickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { | |
// first check for image from camera roll or camera | |
UIImage *image = [info objectForKey:@"FPPickerControllerOriginalImage"]; | |
// if not found, check to see if the image has been downloaded | |
if(!image) { | |
NSData *localData = [NSData dataWithContentsOfURL:[info objectForKey:@"FPPickerControllerReferenceURL"]]; | |
if(localData) { | |
image = [UIImage imageWithData:localData]; | |
} | |
} | |
if (image) { | |
// if the image is found, dismiss the modal vc and fire the delegate to save and display the image | |
[self dismissImagePicker]; | |
self.selectedPhotoFromCamera = image; | |
[self.delegate imageSelectedFromCamera:self]; | |
} | |
else { | |
// if the image is not found, attempt to load it in the background from the remote url | |
[self downloadImageInBackgroundWithUrl:[NSURL URLWithString:[info objectForKey:@"FPPickerControllerRemoteURL"]]]; | |
} | |
} | |
-(void)downloadImageInBackgroundWithUrl:(NSURL*)url { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
UIImage* image; | |
NSData *data = [NSData dataWithContentsOfURL:url]; | |
if(data) { | |
image = [UIImage imageWithData:data]; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self dismissImagePicker]; | |
if(image) { | |
self.selectedPhotoFromCamera = image; | |
[self.delegate imageSelectedFromCamera:self]; | |
} else { | |
[self.delegate errorLoadingImageFromCamera:self]; | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment