如果在第一次询问时拒绝了位置检测,是否有任何方法要求用户授予位置检测权限?Swift - 如果未授予核心位置请求权限
0
A
回答
3
为了得到用户的当前位置,你需要声明:
let locationManager = CLLocationManager()
在viewDidLoad中():
// Ask for Authorisation from the User.
self.locationManager.requestAlwaysAuthorization()
// For use in foreground
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
然后在CLLocationManagerDelegate方法就可以得到用户的当前位置坐标:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var locValue:CLLocationCoordinate2D = manager.location.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
如果用户拒绝了该位置,然后给他选择更改位置pe从设置中删除:
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("error::: \(error)")
locationManager.stopUpdatingLocation()
let alert = UIAlertController(title: "Settings", message: "Allow location from settings", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
alert.addAction(UIAlertAction(title: TextMessages().callAlertTitle, style: .Default, handler: { action in
switch action.style{
case .Default: UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
case .Cancel: print("cancel")
case .Destructive: print("destructive")
}
}))
}
0
不,您可以在提醒内部的应用程序中提醒他们,例如“为了更好的使用,我们会建议您给我们使用您的位置的权限”。并添加“转到设置”按钮,将用户重定向到应用程序的位置权限。
相关问题
- 1. Alert Box要求用户授予位置权限不显示
- 2. ANDROID未授予权限
- 3. PackageManager:未授予权限
- 4. Android - 未授予URI权限
- 5. 授予Oracle授予权限
- 6. IIS7未能授予最小的权限请求
- 7. 核心位置管理不授权
- 8. 如何授予在Oracle中授予权限的权限
- 9. AH01626:要求所有授予的授权结果:授予
- 10. MySQL - 授予权限
- 11. mysql授予权限
- 12. 授予LIST权限
- 13. 授予dbms_crypto权限
- 14. 未经授权的结果AJAX请求
- 15. 授予权限,如Linux
- 16. 如何授予discoverUserInfoWithUserRecordID权限?
- 17. 申请授予临时权限
- 18. ORA-01952:系统权限未授予'ROJIB
- 19. 测试尚未授予的Facebook权限
- 20. 未自动授予摄像头权限
- 21. java - 已截图,但未授予权限?
- 22. 授予Android权限 - 未知值
- 23. MVC核心授权
- 24. Ajax Post请求未授权
- 25. 如果未授予权限,请停止上载到SQL数据库
- 26. 验证用户使用FB.getLoginStatus授予请求的权限
- 27. 请求授予权限时,不会显示requestpermission对话框
- 28. 如何在授予位置权限后执行任务ios
- 29. perl DBI授予权限
- 30. 授予权限的路径
这是认真的答案? –
@NumanKaraaslan是的。如果你仔细阅读,你会发现这是接受答案的简短变体。 – Lexorus