Can';t使用iOS 8.3中的AssetsLibrary编辑照片元数据(在8.2中使用)
我的应用程序拍摄照片,将其保存到相机卷,并允许修改EXIF元数据 我使用AssetLibrary保存和修改照片(我不能使用新的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也没有返回错误,我检查照片是否可编辑 代码如下:Can';t使用iOS 8.3中的AssetsLibrary编辑照片元数据(在8.2中使用),ios,objective-c,assetslibrary,Ios,Objective C,Assetslibrary,我的应用程序拍摄照片,将其保存到相机卷,并允许修改EXIF元数据 我使用AssetLibrary保存和修改照片(我不能使用新的PhotoKit api,因为我需要修改底层的EXIF,而且它是一个遗留应用程序,需要进行大量重构才能更改) 我使用的是Xcode 6.3.1,iOS 8.3 SDK,部署目标为6.1 在iOS 8.2中,所有这些都起到了作用 在iOS 8.3中,元数据的编辑失败 应用程序在隐私设置中具有访问照片的权限 当用户修改照片时,应用程序尝试重写照片,iOS 8.3现在显示“允许
-(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];
}
}
在调试时,我注意到我的代码中有一个bug,UIImageJPEGRepresentation将照片大小增加了4倍,因为它正在对照片进行重新采样,所以我更改了代码以获取原始图像字节,并重写了元数据。但有趣的是,我得到了一个不同的错误,这次setImageData返回这个错误
说明:“用户拒绝访问”
基本错误:“AlassetLibraryErrorDomain”代码-3311
失败原因:“用户已拒绝应用程序访问其媒体”
这很奇怪,因为应用程序创建了资源,并且它可以访问相机卷
同样,此代码适用于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];
}
}
我向苹果提交了一份bug报告,但没有得到任何回复
这与这个问题类似:
有人知道这个问题的解决方法吗
谢谢,请将错误报告的URL共享给苹果。我也遇到了类似的问题。我可以从使用“EnumerateAssetsingBlock”生成的数组中访问资源。但是当我使用“assetForURL”时(仅在ios8.3中),我得到了零资产。不知道如何共享错误URL,错误编号是:20552205