ios - 当用户退出地理围栏时触发事件

标签 ios gps geofencing

有没有办法在 iOS 设备的当前位置周围定义地理围栏(中心和半径),并让系统在设备退出地理围栏时在我的应用程序中触发回调函数?这种机制是否可以唤醒已关闭的应用程序?

我想避免大量使用 GPS,所以我更喜欢系统消息而不是定期 GPS 轮询,即使以降低准确性为代价也是如此。

最佳答案

您的解决方案是 Region Monitoring .

In iOS, regions associated with your app are tracked at all times, including when your app is not running. If a region boundary is crossed while an app is not running, that app is relaunched into the background to handle the event. Similarly, if the app is suspended when the event occurs, it is woken up and given a short amount of time (around 10 seconds) to handle the event.

每当应用程序请求区域监控时,iOS 就会响应。您的应用程序注册了一些位置并要求 iOS 监控该区域并在进入或退出该区域时准确通知。

喜欢 CLRegion *region = [[CLCircularRegion alloc] initWithCenter:[location coordinate] radius:250.0 identifier:[[NSUUID UUID] UUIDString]];

现在 iOS 接收此请求并将其添加到区域监控的系统队列中,并为您的应用程序提供内部标识。一旦设备进入该区域或离开该区域,iOS 就会向应用程序发送通知以启动并解雇代表。

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region

请注意,如果您的应用程序在后台运行,一旦设备进入/离开注册区域,iOS 将使您的应用程序在后台启动。

这是关于 FourSquare 和其他类似应用程序如何尝试执行大量位置数据收集并将其发送到服务器并在短时间内为用户提供定制消息的关键点之一。

关于ios - 当用户退出地理围栏时触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22907464/

相关文章:

ios - Parse.com 查询未加载

android - 仅使用 GPS 的地理围栏在 Android 中不起作用

ios - 如何在 SWIFT 项目中使用 iosMath?响应。如何将 MTMathUILabel() 添加到项目中?

javascript - 使用 Javascript 保存跟踪的 GPS 数据

android - 获取坐标的平均精度

Javascript : How do I map gps coordinates to an image

没有 requestLocationUpdates 不会触发 Android 地理围栏

iOS Geofence CLCircularRegion 监控。位置管理器 :didExitRegion does not seem to work as expected

iphone - 无法显示异步加载的纹理

android - CC41-A 拒绝配对