Getting the URL of picture taken by camera with Photos Framework
UPDATE: Seems like I found an answer to this Problem.
Step 1: I save the image to the camera
UIImageWriteToSavedPhotosAlbum(image.image, self, #selector(cameraImageSavedAsynchronously), nil)
this is done asynchronously, so make sure to set a selector when operation has finished.
Step 2: When operation has 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 fetch the last image in camera roll with PHAsset and save the local identifier of the image. This is not an URL, but a unique identifier which does not change. This way, you can access the saved image perfectly.
Hope this helps others!