无法使用iOS 8.3中的AssetsLibrary编辑照片元数据(在8.2中使用)

我的应用程序拍摄照片,将它们保存到相机胶卷,并允许修改EXIF元数据。

我使用AssetsLibrary来保存和修改照片(我不能使用新的PhotoKit api,因为我需要修改底层的EXIF,加上它是一个遗留的应用程序,需要大量的重构来改变它)。

我正在使用Xcode 6.3.1,iOS 8.3 SDK,部署目标为6.1。

在iOS 8.2中,所有这些都有效。

在iOS 8.3中,元数据的编辑失败。

该应用在“隐私”设置中拥有访问照片的权限。

当用户修改照片,并且应用程序尝试重写照片时,iOS 8.3现在会显示“允许应用程序修改此照片”对话框。 此对话框未出现在iOS 8.2中。 如果单击“修改”,则会保存照片,但会擦除元数据。 setImageData也没有返回错误,我检查照片是否可编辑。

这是代码:

-(void)savePhoto:(ALAsset*)asset { ALAssetRepresentation* rep = [asset defaultRepresentation]; CGImageRef imageRef = [rep fullResolutionImage]; UIImage *image = [UIImage imageWithCGImage:imageRef]; NSData *imageData = UIImageJPEGRepresentation(image, 1.0); if ([asset isEditable]) { [asset setImageData:imageData metadata:self.getMetadataDictionary completionBlock:^(NSURL *assetURL, NSError *error) { if (error!=nil) [self showErrorDialog:error title:@"Error saving photo" ]; [self closeSaveDialog]; }]; } else { [self closeSaveDialog]; UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error saving photo" message:@"Photo is not editable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } 

在调试时,我注意到我的代码中的一个错误,即UIImageJPEGRepresentation将照片大小增加了4倍,因为它正在重新采样照片,因此我更改了代码以获取原始图像字节,然后重写元数据。 但有趣的是,我得到了一个不同的错误,这次setImageData返回此错误。

描述:“用户拒绝访问”。

基础错误:“ALAssetsLibraryErrorDomain”代码-3311。

FailureReason:“用户拒绝了应用程序访问其媒体”。

这很奇怪,因为应用程序创建了资产,并且它已经适应了相机胶卷。

同样,此代码适用于iOS 8.2:

 -(void)savePhoto:(ALAsset*)asset { ALAssetRepresentation* rep = [asset defaultRepresentation]; // New way handling updating photos, doesn't modify image data at all, only metadata Byte *buffer = (Byte*)malloc((unsigned long)rep.size); NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:(NSUInteger)rep.size error:nil]; NSData *imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; if ([asset isEditable]) { [asset setImageData:imageData metadata:self.getMetadataDictionary completionBlock:^(NSURL *assetURL, NSError *error) { if (error!=nil) [self showErrorDialog:error title:@"Error saving photo" ]; [self closeSaveDialog]; }]; } else { [self closeSaveDialog]; UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error saving photo" message:@"Photo is not editable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } 

我向Apple提交了一份错误报告,但没有回复任何消息。

这类似于这个问题: 在iOS 8.3中setImageData失败

有谁知道修复此问题?

谢谢,