Guest User

Untitled

a guest
Jan 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. switch CLLocationManager.authorizationStatus() {
  2. case .notDetermined:
  3. locationManager.requestWhenInUseAuthorization() // First time lanch app need to get authorize from user
  4. fallthrough
  5. case .authorizedWhenInUse:
  6. locationManager.startUpdatingLocation() // Start location
  7. case .denied:
  8. let alertController = UIAlertController (title: "定位失敗", message: "無法取得使用者目前所在位置", preferredStyle: .alert)
  9.  
  10. let settingsAction = UIAlertAction(title: "設定", style: .default) { (_) -> Void in
  11.  
  12. guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
  13. return
  14. }
  15.  
  16. if UIApplication.shared.canOpenURL(settingsUrl) {
  17. UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
  18. print("Settings opened: \(success)") // Prints true
  19. })
  20. }
  21. }
  22. alertController.addAction(settingsAction)
  23. let cancelAction = UIAlertAction(title: "確認", style: .default, handler: nil)
  24. alertController.addAction(cancelAction)
  25.  
  26. present(alertController, animated: true, completion: nil)
  27. default:
  28. break
  29. }
Add Comment
Please, Sign In to add comment