即使应用未运行,这里的任何人都无法使用位置服务-使用重大位置更改吗?基本上,我正在运行该应用程序,收集(确认)位置数据,然后完全关闭该应用程序。在下面设置代码。
class LocationService: NSObject, CLLocationManagerDelegate {
public static let shared = LocationService()
var delegate: LocationServiceDelegate?
var locationManager: CLLocationManager!
var currentLocation: CLLocation!
private var startTime: Date?
private let apiService = APIService()
private override init() {
super.init()
self.setUpLocationServices()
}
private func setUpLocationServices() {
self.locationManager = CLLocationManager()
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestAlwaysAuthorization()
self.locationManager.allowsBackgroundLocationUpdates = true
self.locationManager.pausesLocationUpdatesAutomatically = false
self.locationManager.delegate = self
self.locationManager.startUpdatingLocation()
//self.locationManager.startMonitoringSignificantLocationChanges()
}
// in app delegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("starting launching options")
return true
}
func applicationWillTerminate(_ application: UIApplication) {
self.locationManager.startMonitoringSignificantLocationChanges()
self.locationManager.stopUpdatingLocation()
}
据我了解,标准服务和重要服务都可以串联运行(文档说重要监视将忽略期望的准确性和过滤器)。但是,我确实尝试使用主AppDelegate中的一些位置管理器委托方法来分别停止和启动标准服务和重要服务,但它似乎仍然不起作用。
我具有所有必需的使用说明,并在“后台模式的功能”下选中了“位置更新”。我还确保在收到隐私提示时,选择“始终允许”。
我昨晚开车去了10分钟,距离超过500m,该应用程序并未在后台重新启动。我也使用Freeway模式(在208上)在模拟器(iOS 12.2)下进行了尝试,但仍然无法正常工作,即使30分钟后我也没有收到新的定位事件。关于如何使它正常工作的任何线索,或者我想念的其他任何东西?
我知道以前有一些与此相关的文章,但其中大多数是过时的。不知道自iOS 8/9以来是否发生了某些变化?
@ cspam
您能给我们代码如何工作吗?我正在尝试使此工作正常,但即使我执行了startMonitoringSignificantLocationChanges ...,似乎也不会触发我的应用程序委托。
那将非常好!!