我正在使用Swift语言开发iOS应用程序,并且必须在初始屏幕中检查位置访问权限。
用户接受共享位置后,如何推送到另一个视图控制器,否则显示以下警报来通知用户?


  请在“设置”应用中启用GPS


在splashScreen中,我使用了以下代码:

let LocationMgr = LocationSingleton.sharedInstance //location
let status = CLLocationManager.authorizationStatus()

switch status {
// 1
case .notDetermined:
    LocationMgr.locationManager!.requestWhenInUseAuthorization()
    break
// 2
case .denied, .restricted:
    let alert = UIAlertController(title: "Location Services disabled", message: "Please enable Location Services in Settings", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
    alert.addAction(okAction)

    present(alert, animated: true, completion: nil)
    break
case .authorizedAlways, .authorizedWhenInUse:
    //I want to push to another view
    break
}

// 4
LocationMgr.delegate = self
LocationMgr.startUpdatingLocation()


用户选择(authorizedAlwaysauthorizedWhenInUse)然后推送到另一个视图后,如何检查是否启用了位置服务?

最佳答案

如果使用情节提要

在情节提要中,在初始屏幕和下一个屏幕之间创建一个Segue。右键单击并从控制器图标拖动到下一个屏幕。和

ios - 在Swift中分享位置-LMLPHP

并输入一个标识符:

ios - 在Swift中分享位置-LMLPHP

然后在您的switch语句中:

performSegue(withIdentifier: "showNextScreen", sender: nil)

关于ios - 在Swift中分享位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59017514/

10-14 20:50
查看更多