带GPS数据的uiimagePickerController(Swift)

时间:2014-12-03 15:12:51

标签: ios swift gps

我要感谢是否有人可以提供帮助。我正在从https://www.youtube.com/watch?v=ztIBNHOm35Ehttps://github.com/TDAbboud/PhotosGalleryApp

学习这个非常好的快速示例代码

我正在关注所选相机胶卷照片中的GPS数据。哪个应用程序需要使用 imagePickerController 选择任何照片并放入App Album。但是以下功能中缺少GPS数据(从相机胶卷中选取照片然后放入应用相册)。

我的问题:如何使用imagePickerController包含GPS以在新专辑中创建照片/图像。

Code Here

//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)
  }
}

2 个答案:

答案 0 :(得分:2)

试试这个:

请记住Human

import AssetsLibrary

答案 1 :(得分:0)

更改

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){