gpt4 book ai didi

ios - 使用 Swift 切换 CoreLocation

转载 作者:行者123 更新时间:2023-11-29 02:23:03 27 4
gpt4 key购买 nike

当您在我的 swift 应用程序中按下按钮时,我试图打开和关闭 CoreLocation。当应用程序加载时,这就是我打开它的方式

let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()

if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}

这很好用。它提示用户然后更新我在 map 上的位置。但是,如果您在请求时选择“否”,我希望能够再次打开它。我认为这就像再次请求授权一样简单,但它不起作用。我有一个方法,当按下按钮打开位置时会调用该方法。

这个方法的代码本质上是完全一样的。最初设置授权状态后,我需要做一些不同的事情吗?

最佳答案

if you were to choose "No" when it requests, I want to be able to then turn it back on again

一旦用户选择拒绝您的授权,您就不能神奇地反驳用户,而且(唉)您不能让系统的授权对话框再次出现。

您能做的最好的事情就是设置您自己的对话框(即警报)请求用户转到“设置”并拨动开关以授予您授权。您甚至可以将用户带到“设置”(iOS 8 中的新增功能)。但您无法再次获得该系统授权对话框。

关于ios - 使用 Swift 切换 CoreLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891784/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com