当拍摄照片(iOS 8.1)并调用 didFinishPickingMediaWithInfo 时,我正在尝试使用 PhotoKit 将 GPS 数据重新添加到元数据中。
这是我正在使用的代码:
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *newAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
newAssetRequest.creationDate = [NSDate date];
newAssetRequest.location = [self deviceLocation];
NSLog(@"didFinishPickingMediaWithInfo: location:%@", newAssetRequest.location);
PHObjectPlaceholder *placeholderAsset = newAssetRequest.placeholderForCreatedAsset;
PHAssetCollectionChangeRequest *addAssetRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:self.myResults[0]];
[addAssetRequest addAssets:@[placeholderAsset]];
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"didFinishPickingMediaWithInfo: Success saving picture to album");
} else {
NSLog(@"didFinishPickingMediaWithInfo: error saving picture to album %@", error);
}
}];
[picker dismissViewControllerAnimated:YES completion:nil];
该代码获取图像并将其移动到相册。这部分有效。照片最终出现在正确的相册中。
问题是即使位置属性设置正确,元数据中也不存在 GPS 数据。我知道位置数据是有效的。
这不应该工作吗?是否有替代方法来获得所需的结果?我并不关心所有其他元数据,只关心 GPS 坐标。