我要感谢是否有人可以提供帮助.我正在从https://www.youtube.com/watch?v=ztIBNHOm35E 或https://github.com/TDAbboud/PhotosGalleryApp学习这个非常好的快速示例代码
我正在关注所选相机胶卷照片中的GPS数据.哪个App需要使用imagePickerController选择任何照片并放入App Album.但是以下功能中缺少GPS数据(从相机胶卷中选取照片然后放入应用相册).
我的问题:如何使用imagePickerController包含GPS在新专辑中创建照片/图像.

//UIImagePickerControllerDelegate Methods
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){
// http://stackoverflow.com/questions/26391158/getting-metadata-in-swift-by-uiimagepickercontroller?rq=1
let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary //Try to get gps info
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
//Implement if allowing user to edit the selected image
//let editedImage = info.objectForKey("UIImagePickerControllerEditedImage") as UIImage
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0), {
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset
let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection, assets: self.photosAsset)!
albumChangeRequest.addAssets([assetPlaceholder!])
}, completionHandler: {(success, error)in
dispatch_async(dispatch_get_main_queue(), {
NSLog("Adding Image to Library -> %@", (success ? "Sucess":"Error!"))
picker.dismissViewControllerAnimated(true, completion: nil)
})
})
})
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!){
picker.dismissViewControllerAnimated(true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
记得import AssetsLibrary
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
picker.dismissViewControllerAnimated(true, completion: { () in
if (picker.sourceType == .PhotoLibrary) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let library = ALAssetsLibrary()
var url: NSURL = info[UIImagePickerControllerReferenceURL] as! NSURL
library.assetForURL(url, resultBlock: { (asset: ALAsset!) in
if asset.valueForProperty(ALAssetPropertyLocation) != nil {
let latitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.latitude
let longitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.longitude
println("\(latitude), \(longitude)")
}
},
failureBlock: { (error: NSError!) in
println(error.localizedDescription)
})
}
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2305 次 |
| 最近记录: |