我有同樣的問題獲取所選照片的文件名。對於新拍攝的圖片,UIImagePickerControllerReferenceURL將返回nil,因爲NSURL不存在,所以我分配一個默認名稱。它referenceUrl存在,我得到了在Photos Framework中引入的PHImageManager的幫助文件名。
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)
}
}
你是在說爲什麼它生病了,但沒有提及我們如何擺脫它?你能幫忙嗎? – Umitk