Skip to content

Instantly share code, notes, and snippets.

@ysam12345
Last active January 9, 2019 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysam12345/61262777315ff2d4188dab232791aed3 to your computer and use it in GitHub Desktop.
Save ysam12345/61262777315ff2d4188dab232791aed3 to your computer and use it in GitHub Desktop.
locationManager = CLLocationManager()
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestAlwaysAuthorization()
}
// 2. 用戶不同意
else if CLLocationManager.authorizationStatus() == .denied {
DispatchQueue.main.async(){
let alertController = UIAlertController(title: "定位權限已關閉", message: "如要變更權限,請至 設定 > 隱私權 > 定位服務 開啟", preferredStyle: .alert)
let okAction = UIAlertAction(title: "ok", style: .default, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}//DispatchQueue
}
// 3. 用戶已經同意
else if CLLocationManager.authorizationStatus() == .authorizedAlways {
locationManager.startUpdatingLocation()
}
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(MapTableViewController.mapLongPress(_:))) // colon needs to pass through info
longPress.minimumPressDuration = 1.0 // in seconds
mapView.addGestureRecognizer(longPress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment