2017-01-02 6 views
1

ユーザーの場所に基づいてデータを表示するアプリがあります。そしてそれは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 
} 
+0

> 1kmを移動したり移動したりしましたか? – shallowThought

+0

ちょうど静的な位置と動きをシミュレートしようとしましたが、データが提示されていますが、なぜこれがシミュレーションなしでも機能しないのか分かりません。 – Kmkrn

+0

あなたの新しい情報で質問を編集することがあります。質問は "CLLocationManagerはiOS10の下で最初の場所を報告しません" – shallowThought

答えて

0

viewDidLoad()のうち、すべてのlocationManagerデリゲートの機能を取る:

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() 
} 

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) { 
    ... 
} 

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    ... 
} 

も実装しています

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 
    print("Failed: \(error.localizedDescription)") 
} 

をあなたに実行する可能性のあるエラーを参照してください。

+0

実際のコードでは、実際のコードに入力ミスがあり、まだ動作していません。 – Kmkrn

+0

エラーは出力されません。また、CLManagerをインスタンス化する場所を示します。 – shallowThought

+0

残念ながら、エラーで失敗することはなく、何も印刷されません。 – Kmkrn

関連する問題