I am trying to prevent iOS from showing the following dialog when pictures taken with the app are edited by the user:
According to Apple's documentation for PHContentEditingOutput:
If your app edits the contents of assets already in the Photos library—including assets your app has itself recently added—Photos prompts the user for permission to change the asset’s content. If instead your app uses the initWithPlaceholderForCreatedAsset: method to create an asset with edited content, Photos recognizes your app’s ownership of the content and therefore does not need to prompt the user for permission to edit it.
However, I seem to always get the permission dialog. This is code for adding the picture to the photo library:
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)
})
To edit the picture I use:
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)
})
})
This last part always triggers the system dialog. What can I do to prevent the alert from showing?