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