I am trying to save a photo with a custom file name using iOS 9 PHAssetCreationRequest with .addResourceWithType and Swift 2. It keeps the photo in order, but does not use the file name that I specify in the PHAssetResourceCreationOptions options. I want to use a custom file name, since I need to save a custom photo string that indicates what type of photo it is. At the moment, I save the “type” along with its local identifier in the master data store, however, if the application is deleted, it is the master data store, so I'm looking for an additional method that stays with the photo. Here is the code I'm using:
var assetPlaceholder:PHObjectPlaceholder!
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
if #available(iOS 9.0, *) {
let options = PHAssetResourceCreationOptions()
options.originalFilename = frameType + "_" + origFilename
let newcreation:PHAssetCreationRequest = PHAssetCreationRequest.creationRequestForAsset()
newcreation.addResourceWithType(PHAssetResourceType.Photo, data:UIImageJPEGRepresentation(image, 1)!, options: options)
assetPlaceholder = newcreation.placeholderForCreatedAsset
} else {
let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
assetPlaceholder = assetChangeRequest.placeholderForCreatedAsset
}
let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: assetCollection)
albumChangeRequest!.addAssets([assetPlaceholder])
}, completionHandler: {(success:Bool, error:NSError?) in