UPDATE: It seems I found the answer to this problem.
Step 1: I save the image on the camera
UIImageWriteToSavedPhotosAlbum(image.image, self, #selector(cameraImageSavedAsynchronously), nil)
this is done asynchronously, so be sure to set the selector when the operation is complete.
Step 2: When the operation is completed, I do the following:
func fetchLastImage(completion: (localIdentifier: String?) -> Void) { let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] fetchOptions.fetchLimit = 1 let fetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions) if (fetchResult.firstObject != nil) { let lastImageAsset: PHAsset = fetchResult.firstObject as! PHAsset completion(localIdentifier: lastImageAsset.localIdentifier) } else { completion(localIdentifier: nil) } }
I take the last image in the camera frame using PHAsset and save the local image identifier. This is not a URL, but a unique identifier that does not change. This way you can access the saved image.
Hope this helps others!
source share