I am trying to go through and clean up some deprecation warnings by updating ALAsset with PHPhoto. I am getting confused by this code and need some help to make sure I am not missing something. I added in some comments about what is confusing me.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *assetsURL = [info objectForKey:UIImagePickerControllerReferenceURL];
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
// This is where I am getting confused.
// What is the difference between the meta data of the else statement
// and the if statement.
if (assetsURL) {
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
[library assetForURL:assetsURL
resultBlock:^(ALAsset *asset) {
[metadata addEntriesFromDictionary:asset.defaultRepresentation.metadata];
dispatch_semaphore_signal(sema);
}
failureBlock:^(NSError *error) {
dispatch_semaphore_signal(sema);
}];
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else {
[metadata addEntriesFromDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
}
// Undocumented method guessing it rotates image to Portrait
pickedImage = [pickedImage IN_rotateToPortraitOrientation];
[metadata setImageOrientation:UIImageOrientationUp];
if (!assetsURL) {
[library writeImageToSavedPhotosAlbum:pickedImage.CGImage
metadata:metadata
completionBlock:^(NSURL *assetURL, NSError *error) {
$l(@"Saved to photo album");
}];
}
...
}
If you could help me understand the difference in meta data. If there is a difference how could I accomplish the same thing with PHPhotos.