在设置中启用后,位置信息请求不会出现

我只是从SwiftUI和应用程序开发入手。在我的应用中,我正在检查CLAuthorizationStatus。如果状态被拒绝或限制,则显示警报并指导用户进行设置。

当用户选择始终授权并返回到应用程序时,它可以正常工作并获得地理位置。

但是,当用户在设置中选择“从不”或“始终询问”并返回到应用程序时,我想强制应用程序重新加载并重新检查权限,因为如果用户选择了“始终询问”,该应用程序应该完全做到这一点,事实并非如此。在这种情况下,它保持为“ .notDetermined”。

这是我的Locationmanager类中的一些代码:

class Locationmanager: NSObject,ObservableObject {

    .....

    override init() {
        super.init()
        self.locationmanager.delegate = self
        self.locationmanager.desiredaccuracy = kCLLocationaccuracyBest
        self.locationmanager.requestWhenInUseAuthorization()
        self.locationmanager.startUpdatingLocation()
    }

....
}
func locationmanager(_ manager: CLLocationmanager,didChangeAuthorization status: CLAuthorizationStatus) {
        self.locationStatus = status

        switch status {
            case .notDetermined:
                break
            case .authorizedWhenInUse,.authorizedAlways:
              if CLLocationmanager.locationServicesEnabled() {
                  self.locationmanager.startUpdatingLocation()
                }
            case .restricted,.denied:
                showPermissionAlert()
        default: break
        }

        print(#function,statusString)
    }

我如何设法强制返回到应用程序的请求?退出并重新启动确实会带来请求窗口,但不会从设置中返回。

提前谢谢!

cugdonjuan 回答:在设置中启用后,位置信息请求不会出现

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3152530.html

大家都在问