I'm writing a test application to see if it is possible to delete a "photo library" asset in iOS 8, using the Photos framework. Although I suspect it is not possible, I find the documentation to be unclear, and there are posts on this site that seem to indicate it is possible. See here for example.
In my test app, I pick an asset from the library:
var picker = UIImagePickerController()
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picker.mediaTypes = [kUTTypeMovie]
In the delegate callback, I get the NSURL of the asset, and put it into an array:
let thePicked = info[UIImagePickerControllerMediaURL] as NSURL!
var videosToDelete: [NSURL] = [theURL]
And here is the part I'm least confident about, where I get the PhotoLibrary, and do a change request to delete the asset:
PHPhotoLibrary.sharedPhotoLibrary().performChanges( {
let assetToDelete = PHAsset.fetchAssetsWithALAssetURLs(videosToDelete, options: nil)
PHAssetChangeRequest.deleteAssets(assetToDelete)
},
completionHandler: { success, error in
NSLog("Finished deleting asset. %@", (success ? "Success" : error))
})
The completion handler returns successfully, but the asset is never deleted. Am I doing something wrong? Or am I trying to do something inherently not allowed, and I'm not receiving the correct feedback for it?