我正在玩新的iOS 8照片框架,试图编辑我的库中的现有照片然后替换它但它没有被替换,即使我能看到所有成功的日志消息我&# 39; ve set。
这是我的代码:
UIImage *output = [self.imageView.image appendDateWithLabel:label];
self.imageView.image = output;
// self.info was retrieve by the UIImagePickerController delegate method
NSURL *assetURL = self.info[UIImagePickerControllerReferenceURL];
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL] options:nil];
PHAsset *asset = result.firstObject;
if ([asset canPerformEditOperation:PHAssetEditOperationContent])
{
[asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
PHContentEditingOutput *contentEditingOutput = [[PHContentEditingOutput alloc] initWithContentEditingInput:contentEditingInput];
NSData *outputData = UIImagePNGRepresentation(output);
BOOL wrote = [outputData writeToURL:contentEditingOutput.renderedContentURL options:NSDataWritingAtomic error:nil];
if (wrote)
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *request = [PHAssetChangeRequest changeRequestForAsset:asset];
request.contentEditingOutput = contentEditingOutput;
} completionHandler:^(BOOL success, NSError *error) {
// console output : 1
NSLog(@"success : %@", @(success));
// console output : nil
NSLog(@"error : %@", error);
}];
}
}];
}
我没有替换,而是尝试创建修改后的副本。这很有效,我可以在我的图书馆看到新修改过的照片。
有人已经遇到过这个问题吗?
答案 0 :(得分:4)
为了编辑照片,似乎必须填写adjustementData
对象的PHContentEditingOutput
属性。
PHAdjustmentData *adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"AdjustementDataIdentifier" formatVersion:@"1.0" data:nil]