如何在 Xamarin iOS 中启动由 iBeacon 触发的 GPS 跟踪?

How to start GPS tracking triggered by a iBeacon in Xamarin iOS?

我正在开发一个通过跟踪 GPS 记录旅程的应用程序。如果我们从前台启动进程(通过点击按钮"Start Journey"),后台一切正常。 现在的想法是开始记录这些由 iBeacon 自动触发的旅程。当 iPhone 进入信标区域内时,应用程序会检测到这一点并调用函数 LocationManager.StartUpdatingLocation();

问题: 从后台使用 iBeacons,我们只有 10 秒的测距时间,这与我从 GPS 获取位置更新的时间相同。

我所需要的只是检测到我在信标区域内,启动 GPS 并保持它 运行,并且仅当我在该区域之外时才禁用 GPS。

我看到的对此的最佳解释可以将 10 秒延长到 3 分钟,但就是这样......应用拒绝是持续后台运行的一个问题,除非你的应用真正被审查为导航应用:

A second approach involves tracking the beacon in the background, noting its estimated distance, and only triggering an action when the beacon is estimated to be within a specific range. This approach is problematic on iOS, because CoreLocation generally allows only 10 seconds of ranging time when an app is in the background. If a beacon is first detected at 50 meters, and a person is approaching the beacon at one meter per second, the mobile device will still be 40 meters away when iOS suspends the app and stops it from ranging.

The good news is that it is possible to extend background ranging time on iOS. If your app is a navigation app, you can specify location updates in the “Required background modes” in your Info.plist. But this approach makes it harder to get AppStore approval -- you have to convince reviewers that your app is providing navigation services to the user. This probably isn’t true for many apps that simply want to use beacons to trigger at a specific distance.

Fortunately, you can still extend background ranging time without requesting special background modes. The time you can get is limited -- only three minutes. But this clock restarts each time your app is woken up in the background, meaning you can get an extra three minutes of ranging time each time your app detects a beacon (enters a beacon region) or stops seeing beacons (exits a beacon region.)

通过:http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html

不幸的是,您可以在后台使用 CoreLocation 地理围栏,但您无法持续获得精确的 GPS 更新。这不是 Xamarin 的东西——它是一个 iOS 限制。

我写了博客 post,@RobertN 引用了关于将背景信标范围扩展到 3 分钟的内容。但我不认为这对你有多大帮助,因为你想不断获得 GPS 更新,而 Apple 根本不允许。

实际上我们最近也想在我们的一个应用程序中实现此行为,并且发现如果我们在前台开始重要的位置更新 (startMonitoringSignificantLocationChanges),那么我们就能够开始定期位置更新(startUpdatingLocation) 在后台,在我们的 didEnterRegion 实现中。

(当然,您的应用需要 "always" 授权才能访问定位服务,并且启用 "Location updates" 后台模式。)

我们的应用程序仍在等待审核,因此这是 Core Location 的错误还是功能,以及 Apple 是否同意,还有待观察。