選択した写真のファイル名を取得するのと同じ問題がありました。新しく撮影した写真の場合、NSURL が存在しないため UIImagePickerControllerReferenceURL は nil を返すため、デフォルトの名前を割り当てます。フォト フレームワークで導入された PHImageManager の助けを借りてファイル名を取得する referenceUrl が存在します。
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
self.selectedIndex = 1
var fileName = UIImage.defaultFileName()
//Pic is comming from library so url exists
if let referenceUrl = info[UIImagePickerControllerReferenceURL] as? NSURL, image = info[UIImagePickerControllerOriginalImage] as? UIImage {
if #available(iOS 8.0, *) {
let phAsset = PHAsset.fetchAssetsWithALAssetURLs([referenceUrl], options: nil).lastObject as! PHAsset
PHImageManager.defaultManager().requestImageDataForAsset(phAsset, options: PHImageRequestOptions(), resultHandler: { (imagedata, dataUTI, orientation, info) in
if info!.keys.contains(NSString(string: "PHImageFileURLKey")) {
let path = info![NSString(string: "PHImageFileURLKey")] as! NSURL
fileName = path.lastPathComponent!
}
self.addDocumentDelegate?.tabBarControllerDidTakePicture(self, image: image, fileName: fileName)
AppRoot.sharedInstance.dismissModalViewController(true, completion: nil)
})
} else {
self.addDocumentDelegate?.tabBarControllerDidTakePicture(self, image: image, fileName: fileName)
AppRoot.sharedInstance.dismissModalViewController(true, completion: nil)
}
} else if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { //Pic is comming from Camera so url does not exists
self.addDocumentDelegate?.tabBarControllerDidTakePicture(self, image: image, fileName: fileName)
AppRoot.sharedInstance.dismissModalViewController(true, completion: nil)
}
}