iOS向けに、CoreLocationを使ったアプリを開発しています。
ですが、実機ではうまく動くのに、シミュレータだと、locationManager(_:didUpdateLocations:)が2、3回呼ばれてそれ以降監視をしません。
ネットには実機とシミュレータで動作が違うというのもあったのですが、そういうものなのでしょうか。
希望としては、シミュレータでも継続的に監視をして欲しいのです。
そうでないとアプリの審査が通らないのではと思っています。
Swift
1 override func viewDidAppear(_ animated: Bool) { 2 print(#function) 3 if CLLocationManager.locationServicesEnabled() == false { 4 return 5 } 6 7 let status = CLLocationManager.authorizationStatus() 8 if status == CLAuthorizationStatus.restricted || status == return 9 } 10 11 if status == CLAuthorizationStatus.notDetermined { 12 myLocationManager.requestAlwaysAuthorization() 13 } 14 15 if myLocationManager == nil { 16 myLocationManager = CLLocationManager() 17 myLocationManager!.delegate = self 18 myLocationManager!.desiredAccuracy = kCLLocationAccuracyNearestTenMeters 19 myLocationManager!.distanceFilter = 5.0 20 myLocationManager!.allowsBackgroundLocationUpdates = true 21 22 } 23 24 25 } 26 27 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 28 print(#function) 29 30 let lastLocation = locations.last 31 if let last = lastLocation { 32 let eventDate = last.timestamp 33 if let location = manager.location { 34 35 print("(Date()):((location.coordinate.latitude), (location.coordinate.longitude))") 36 37 } 38 } 39 40 } 41 42 @IBAction func onClickStartButton(_ sender: Any) { 43 print(#function) 44 myLocationManager!.startUpdatingLocation() 45 } 46
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。