4

I am trying to prevent iOS from showing the following dialog when pictures taken with the app are edited by the user:

iOS Allow App To Modify Photo Dialog

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jorge
  • 2,530
  • 1
  • 19
  • 28
  • I don't see you calling `initWithPlaceholderForCreatedAsset` anywhere ... – John Hascall Jan 29 '16 at 13:19
  • @JohnHascall that is an Objective-C call. In Swift this line should be equivalent: ```let editingOutput = PHContentEditingOutput(placeholderForCreatedAsset: assetPlaceholder!)``` – Jorge Jan 29 '16 at 15:29
  • Any solution found yet? – iMDroid Oct 11 '17 at 08:38
  • Unfortunately, I have not found one yet. I guess we need to request Apple to soften its policy in regards to this. – Jorge Oct 11 '17 at 13:14

0 Answers0