Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch CLLocationManager.authorizationStatus() {
- case .notDetermined:
- locationManager.requestWhenInUseAuthorization() // First time lanch app need to get authorize from user
- fallthrough
- case .authorizedWhenInUse:
- locationManager.startUpdatingLocation() // Start location
- case .denied:
- let alertController = UIAlertController (title: "定位失敗", message: "無法取得使用者目前所在位置", preferredStyle: .alert)
- let settingsAction = UIAlertAction(title: "設定", style: .default) { (_) -> Void in
- guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
- return
- }
- if UIApplication.shared.canOpenURL(settingsUrl) {
- UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
- print("Settings opened: \(success)") // Prints true
- })
- }
- }
- alertController.addAction(settingsAction)
- let cancelAction = UIAlertAction(title: "確認", style: .default, handler: nil)
- alertController.addAction(cancelAction)
- present(alertController, animated: true, completion: nil)
- default:
- break
- }
Add Comment
Please, Sign In to add comment