0

我正在尝试通过使用 PHPhoto 更新 ALAsset 来清除一些弃用警告。我被这段代码弄糊涂了,需要一些帮助来确保我没有遗漏任何东西。我在一些评论中添加了一些关于什么让我感到困惑的评论。

- (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");
                          }];
}
...
}

如果你能帮助我理解元数据的区别。如果有区别,我怎么能用 PHPhotos 完成同样的事情。

4

0 回答 0