Мое приложение отслеживает местоположение пользователя с помощью CoreLocation
и CoreMotion
фреймворков. В некоторых случаях он отслеживает несуществующие маршруты. Устройство не перемещается, но отправляет местоположение, скорость и тип активности automotive
, как это происходит. Что может вызвать такое поведение?
LocationManager configuration
func update<T>(configuration: T) {
if let configuration = configuration as? LocationManagerConfiguration {
guard configuration.isActive else {
locationManager.stopUpdatingLocation()
return
}
locationManager.desiredAccuracy = configuration.accuracy
locationManager.distanceFilter = configuration.distanceFilter
}
}
Места обработки
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var isAccepted = false
for loc in locations where filtersManager.isAcceptable(location: loc) {
print("All filters restrictions satisfied, accepting", logLevel: .DEBUG);
var location = Api_Protobuf_Location()
//setting protobuf model
geoLocation.onNext(location)
isAccepted = true
}
if !isAccepted {
print("Some filters restrictions not satisfied, ignoring", logLevel: .DEBUG);
geoLocation.onNext(nil)
}
}
Деятельность по обработке
func start() {
guard CMMotionActivityManager.isActivityAvailable() else { return }
activityManager.startActivityUpdates(to: OperationQueue.main) { [weak self] result in
guard let result = result else {
self?.activity.onNext((nil, nil))
return
}
let activity: Api_Protobuf_Activity
switch self {
case _ where result.automotive:
activity = .inVehicle
case _ where result.cycling:
activity = .onBicycle
case _ where result.running:
activity = .running
case _ where result.walking:
activity = .walking
case _ where result.stationary:
activity = .still
default:
activity = .unknown
}
self?.activity.onNext((activity, result.confidence.rawValue))
}
pedometer.startUpdates(from: Date()) { [weak self] pedometerData, error in
guard let pedometerData = pedometerData else {
self?.steps.onNext(nil)
return
}
if let error = error {
self?.steps.onError(error)
return
}
let steps = Steps(count: Int(truncating: pedometerData.numberOfSteps),
floorsUp: Int(truncating: pedometerData.floorsAscended ?? -1),
floorsDown: Int(truncating: pedometerData.floorsDescended ?? -1))
self?.steps.onNext(steps)
}
}