我正在使用 Swift 语言开发 iOS 应用程序,我必须在启动屏幕中检查位置访问。在用户接受共享位置后,如何推送到另一个 View Controller ,否则显示以下警报以通知用户?
Please enable GPS in the Settings app
在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
)后检查位置服务是否启用,然后推送到另一个 View ?
如果使用 Storyboard
在 Storyboard中,在初始屏幕和下一个屏幕之间创建一个 Segue。右键单击并从 Controller 图标拖动到下一个屏幕。和
并输入标识符:
然后在你的 switch 语句中:
performSegue(withIdentifier: "showNextScreen", sender: nil)
Tôi là một lập trình viên xuất sắc, rất giỏi!