我已请求(并允许)该应用访问用户位置:
private func allowAccesstoUserLocation() { locationManager = CLLocationManager() locationManager.delegate = self locationManager.requestWhenInUseAuthorization() }
我是否需要询问相机应用程序的具体预设?
编辑:
我使用UIImagePickerController从应用程序中拍摄照片.
从应用程序中拍摄的所有照片都存储在照片库中,没有地理位置.
这与我将图像保存到照片库的方式有什么关系吗?
我的问题在这里而不是在核心位置权限?
func imagePickerController(_ picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [String : Any]) { if let pickedImage = info[UIImagePickerControllerOriginalimage] as? UIImage{ UIImageWritetoSavedPhotosAlbum(pickedImage,self,#selector(image(_:dIDFinishSavingWithError:contextInfo:)),nil) dismiss(animated: true,completion: { self.showPhoto()}) } }解决方法 在iOS 8中,Apple推出了 Photo Library.
以下是使用location创建和更新PHAsset的示例:
func addAsset(image: UIImage,location: CLLocation? = nil) { PHPhotolibrary.shared().performChanges({ // Request creating an asset from the image. let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: image) // Set Metadata location if let location = location { creationRequest.location = location } },completionHandler: { success,error in if !success { NSLog("error creating asset: \(error)") } })}
在保存之前,请确保您有权访问照片
PHPhotolibrary.requestAuthorization(_:)
元数据可以通过以下方式读取:
info[UIImagePickerControllerMediaMetadata]
我无法在我的测试中验证元数据存储位置,即使在允许位置服务的情况下也是如此.在这种情况下,使用CoreLocation可以自己获得真实位置.
总结以上是内存溢出为你收集整理的ios – 将带有地理定位数据的照片保存到照片库Swift 3全部内容,希望文章能够帮你解决ios – 将带有地理定位数据的照片保存到照片库Swift 3所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)