iOS Photos Framework:如何将图像资源恢复为原始资源

时间:2018-01-27 16:59:47

标签: ios objective-c iphone swift photosframework

所有在线文档和示例都展示了如何使用PHContentEditingInput和PHContentEditingOutput编辑/更改资产。我没有找到任何关于将图像重置或恢复到原始图像的信息。写入renderedContentURL的任何内容都被视为编辑,因此不是我想要的。请在此分享我的发现:

1 个答案:

答案 0 :(得分:1)

使用revertAssetContentToOriginal

夫特:

    PHPhotoLibrary.shared().performChanges({
        let request = PHAssetChangeRequest(for:asset)
        request.revertAssetContentToOriginal()
    }, completionHandler: { success, error in
        if !success { print("can't revert asset: \(error)") }
    })

目标C:

     [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
         PHAssetChangeRequest *change = [PHAssetChangeRequest changeRequestForAsset:asset];
         [change revertAssetContentToOriginal];
     } completionHandler:^(BOOL success, NSError *error) {
         NSLog(@"Finished adding asset. %@", (success ? @"Success" : error));
     }];