Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS13向けに位置情報周りを対応しようとしたら苦労した話

nekowen
September 30, 2019

 iOS13向けに位置情報周りを対応しようとしたら苦労した話

YUMEMI.swift #3 ~俺/私がやったiOS 13対応~
https://yumemi.connpass.com/event/142608/

で発表したものです。

nekowen

September 30, 2019
Tweet

More Decks by nekowen

Other Decks in Technology

Transcript

  1. ݖݶͷมߋΛݕ஌ (Optional) func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

    switch status { // Ϣʔβʔ͕ʮৗʹʯબ୒ͨ࣌͠ case .authorizedAlways: break // Ϣʔβʔ͕ʮΞϓϦΛ࢖༻தͷΈʯΛબ୒ͨ࣌͠ case .authorizedWhenInUse: break // Ϣʔβʔ͕ڋ൱ͬͨ࣌ case .denied: break // Ϣʔβʔ͕·ͩݖݶʹ͍ͭͯબ୒͍ͯ͠ͳ͍࣌ case .notDetermined: break // ϖΞϨϯλϧίϯτϩʔϧͳͲͰ੍ݶ͞Ε͍ͯΔͱ͖ case .restricted: break } }
  2. ΍ͬͪ·࣮ͬͨ૷ (.notDeterminedΛϋϯυϦϯά͍ͯ͠ͳ͍ύλʔϯ) override func viewDidLoad() { super.viewDidLoad() self.lm.delegate = self

    self.lm.requestAlwaysAuthorization() } func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { switch status { case .authorizedAlways, .authorizedWhenInUse: manager.startUpdatingLocation() default: break } }
  3. func startCheckIn() { switch CLLocationManager.authorizationStatus() { case .authorizedAlways, .authorizedWhenInUse: self.lm.requestLocation()

    case .notDetermined: self.lm.requestWhenInUseAuthorization() case .denied, .restricted: self.showErrorAlert() } }