2017-12-16 11 views
3

私は実行中のアプリケーションを作成しようとしていますが、startMonitoringSignificantLocationChangesというメソッドを使用したいのですが、ドキュメントにはdidUpdateLocationsというメッセージが表示されないため、何かが不足しています。swift 4でstartMonitoringSignificantLocationChangesを使用する適切な方法は何ですか?

私はCLLocationManagerクラスのstartUpdatingLocationメソッドをうまく使いました。私はそれを私の興味のために完全に使うことができますが、私の実装がうまくいかない理由を理解したいと思います。

だから、私はこのコードを持って:あなたは(1)とのコメントを外し2 FUNCのlocationManagerコメント場合等...

let locationManager = CLLocationManager() 
func determineMyCurrentLocation() { 

    locationManager.delegate = self 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest 
    locationManager.requestAlwaysAuthorization() 
    locationManager.allowsBackgroundLocationUpdates = true 

    print("authorization Status: \(CLLocationManager.authorizationStatus().rawValue)") 

    if CLLocationManager.locationServicesEnabled() { 
     locationManager.startUpdatingLocation() //(1) 
     //(2)locationManager.startMonitoringSignificantLocationChanges() 
     locationManager.distanceFilter = 20 
     //locationManager.start 
     //locationManager.startUpdatingHeading)(
    } 
} 

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { print("yaaay!") } 

を解雇されることはありません。

また、 "プライバシー - 使用時の使用状況の説明"と "プライバシー - 使用時の使用状況の説明"という適切なキーを設定したinfo.plistを持っています。

ありがとうございます。

EDITED:私の質問は不正確でした。 locationManagerプロパティをクラスメンバとして配置し、info.plistのプロパティを完成させました。

+1

ロケーションマネージャはプロパティでなければなりません。関数が終了するときにリリースされるローカル変数ではありません。また、iOS 11の新しい権限キーが必要です - "alwaysandwheninuse" – Paulw11

答えて

1

startMonitoringSignificantLocationChangesは常に承認が必要です。また、「機能」セクションの「バックグラウンドモード」と「ロケーション更新」を有効にする必要があります。また、Privacy - Location Always Usage Descriptionが必要です。これらの2つを試してください。

関連する問題