According to the 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 always get the system alert "Allow app to modify this photo?".
This is how I am adding the photo:
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)
})
Then, to edit it 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 always fires the alert. What I can I do to prevent the alert from showing?