4

当用户编辑使用应用程序拍摄的照片时,我试图阻止 iOS 显示以下对话框:

iOS 允许应用修改照片对话框

根据 Apple 的 PHContentEditingOutput 文档:

如果您的应用编辑照片库中已有资产的内容(包括您的应用最近添加的资产),照片会提示用户更改资产内容的权限。相反,如果您的应用使用 initWithPlaceholderForCreatedAsset: 方法创建具有已编辑内容的资产,则照片会识别您的应用对内容的所有权,因此无需提示用户授予编辑权限。

但是,我似乎总是得到许可对话框。这是将图片添加到照片库的代码:

var assetPlaceholder:PHObjectPlaceholder!  

PHPhotoLibrary.sharedPhotoLibrary().performChanges({  
    let creationRequest = PHAssetCreationRequest.creationRequestForAssetFromImageAtFileURL(NSURL(fileURLWithPath: originalImagePath))  
    assetPlaceholder = creationRequest!.placeholderForCreatedAsset  

    let editingOutput = PHContentEditingOutput(placeholderForCreatedAsset: assetPlaceholder!)  
    editingOutput.adjustmentData = adjustmentData  
    imageData.writeToURL(editingOutput.renderedContentURL, atomically: true)  

    creationRequest!.contentEditingOutput = editingOutput  
}, completionHandler: { (success:Bool, error: NSError?) in  
    handler(assetPlaceholder.localIdentifier, error)  
})  

要编辑我使用的图片:

let inputOptions = PHContentEditingInputRequestOptions()  
inputOptions.networkAccessAllowed = true  
inputOptions.canHandleAdjustmentData = { adjustmentData in  
    return adjustmentData.formatIdentifier == thisAppFormatIdentifier  
}  

asset.requestContentEditingInputWithOptions(inputOptions, completionHandler: { ( editingInput, info) -> Void in  
    let editingOutput = PHContentEditingOutput(contentEditingInput: editingInput!)  

    PHPhotoLibrary.sharedPhotoLibrary().performChanges({  
        let changeRequest = PHAssetChangeRequest(forAsset: asset)  
        editingOutput.adjustmentData = adjustmentData  
        imageData.writeToURL(editingOutput.renderedContentURL, atomically: true)  
        changeRequest.contentEditingOutput = editingOutput  
    }, completionHandler: { (success:Bool, error: NSError?) in  
        handler(error)  
    })  
})  

最后一部分总是触发系统对话框。我可以做些什么来防止警报显示?

4

0 回答 0