在Swift中分享位置

我正在使用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)然后推送到另一个视图之后,如何检查是否启用了位置服务?

zhongyi9927 回答:在Swift中分享位置

如果使用情节提要

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

create Segue

并输入一个标识符:

enter image description here

然后在您的switch语句中:

performSegue(withIdentifier: "showNextScreen",sender: nil)
本文链接:https://www.f2er.com/3042078.html

大家都在问