Написание фотографии с метаданными с помощью Photokit

В настоящее время я использую платформу ALAsset для сохранения изображения из библиотеки фотографий в каталог документов с метаданными. Код, который я использую

ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
[library assetForURL:[NSURL URLWithString:miv.assetURL] resultBlock:^(ALAsset *asset) {
        ALAssetRepresentation *image_representation = [asset defaultRepresentation];
        CGImageSourceRef source = Nil;
        uint8_t *buffer = (Byte*)malloc(image_representation.size);
        NSUInteger length = [image_representation getBytes:buffer fromOffset: 0.0  length:image_representation.size error:nil];
        if (length != 0)  {
          NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:image_representation.size freeWhenDone:YES];              
          NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:(id)[image_representation UTI] ,kCGImageSourceTypeIdentifierHint,nil];              
          // create CGImageSource with NSData
          source = CGImageSourceCreateWithData((__bridge CFDataRef) adata,  (__bridge CFDictionaryRef) sourceOptionsDict);              
        }
        NSDictionary *metadata = [image_representation metadata];
        NSMutableDictionary *metadataAsMutable = [metadata mutableCopy];
        NSMutableDictionary *EXIFDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary];
        NSMutableDictionary *GPSDictionary = [metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
        if(!EXIFDictionary) {
          EXIFDictionary = [NSMutableDictionary dictionary];
        }
        if(!GPSDictionary) {
          GPSDictionary = [NSMutableDictionary dictionary];
        }
        [metadataAsMutable setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
        [metadataAsMutable setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
        CFStringRef UTI = CGImageSourceGetType(source);
        NSMutableData *dest_data = [NSMutableData data];
        CGImageDestinationRef destination CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);                        
        CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) metadataAsMutable);
        BOOL success = NO;
        success = CGImageDestinationFinalize(destination);

        if(!success) {
        }
        [dest_data writeToFile:myImageFileName atomically:YES];
        CFRelease(destination);
        CFRelease(source);
}];

Я хочу преобразовать этот код в Photo Kit. Из моего исследования я обнаружил, что Photo Kit будет обрабатывать запись

PHFetchResult *savedAssets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObjects:imageURLString, nil] options:nil];
[savedAssets enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
[[PHImageManager defaultManager]
     requestImageForAsset:(PHAsset *)asset
     targetSize:desiredSize
     contentMode:PHImageContentModeAspectFit
     options:Nil
     resultHandler:^(UIImage *result, NSDictionary *info) {
         // Write Here
         // The info here has no EXIF or Metadata. So get them
         PHContentEditingInputRequestOptions *editOptions =      
         [[PHContentEditingInputRequestOptions alloc]init];
         editOptions.networkAccessAllowed = YES;
         [asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
             CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
             NSLog(@"metadata: %@", image.properties.description);
             ?? How do I write this to doc folder ?
       }];

     }
}

Ответы на вопрос(1)

Ваш ответ на вопрос