Modifying Photo: Avoid System Alert

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?

Replies

I quit using the Photos Library a year or more ago because this stupid pop-up made my app totally impractical. I was wondering if they ever changed their policy on this -- apparently not. 😠

I believe this only lets you create a new asset with existing edits (adjustment data) in one go, without being prompted twice (once for asset creation, and once for modifying an existing asset). That's what the sample code in the documentation page for that initializer seems to suggest: everything happens within a single performChanges: block...