ユーザーの場所に基づいてデータを表示するアプリがあります。そしてそれはSwift2とiOS9でうまくいきました。現在、CLLocationManagerデリゲートの関数は呼び出されていません。 は、ここに私のコードです:CLLocationManagerはiOS10での初期位置を報告しません(デリゲート関数は呼び出されません)
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self //locationManager is being initialized at the top of class file and is not nil
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
locationManager.startUpdatingLocation() //This line executes from viewDidLoad, but not from delegate function
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) { //This is never called
if CLLocationManager.authorizationStatus() != .authorizedWhenInUse {
locationManager.requestWhenInUseAuthorization()
}else{
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { //This is never called
if updatingLocation == true {
//if location is updating, go next step
}
}
私はプライバシーを有効にしている - ロケーション常に使用法説明とプライバシー - 私のInfo.plistで場所使用中の使用方法説明。コードをテストするために、didUpdateLocationsも起動する必要があるrequestLocationを呼び出そうとしましたが、そうしませんでした。たぶん私は何かが欠けているかもしれませんが、iOS10のCLLocationManager処理に関して何も変更されていないようです。
UPD:その他のコード
class HomeViewController: BaseViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var updatingLocation = true
//other stuff
}
> 1kmを移動したり移動したりしましたか? – shallowThought
ちょうど静的な位置と動きをシミュレートしようとしましたが、データが提示されていますが、なぜこれがシミュレーションなしでも機能しないのか分かりません。 – Kmkrn
あなたの新しい情報で質問を編集することがあります。質問は "CLLocationManagerはiOS10の下で最初の場所を報告しません" – shallowThought