iOS区域监控,监控20多个位置

标签 ios gps location monitoring region

我做了很多谷歌搜索,但没有找到符合我需要的解决方案。 所以我想出了自己的解决方案,但不确定它是否可行。 我需要监控20多个区域。所以第一次,我将开始监控当前用户的位置,我得到 19 个我可以监控的其他可用位置,假设要监控的半径是 100 米。那么现在应该调用委托(delegate) didEnterRegion 吗?我真的不在乎这个。但是当用户从原始位置移动超过 100m 时,委托(delegate) didExitLocation 将被调用,此时,我将更新要监视的新区域(通过将新的当前用户位置发送到服务器,我将获得要监视的新区域列表),并且我仍然会监控这个新用户的位置,并且仍然会获得我可以监控的其他 19 个区域。 这个方案可行吗?有人试过吗? 如果应用挂起并且消耗大量电池,此解决方案是否仍然有效?

最佳答案

这实际上是Apple的建议Core Location Programming Guide :

To work around this limit, consider registering only those regions in the user’s immediate vicinity. As the user’s location changes, you can remove regions that are now farther way and add regions coming up on the user’s path.

但是,后台调用didEnterRegion:时,你得到了多少时间并不清楚,所以不清楚如果运行后台,你是否有时间进行服务器调用。 “显着变化位置服务”信息说:

If you leave the significant-change location service running and your iOS app is subsequently suspended or terminated, the service automatically wakes up your app when new location data arrives. At wake-up time, the app is put into the background and you are given a small amount of time (around 10 seconds) to manually restart location services and process the location data.... Because your app is in the background, it must do minimal work and avoid any tasks (such as querying the network) that might prevent it from returning before the allocated time expires. If it does not, your app will be terminated. If an iOS app needs more time to process the location data, it can request more background execution time using the beginBackgroundTaskWithName:expirationHandler: method of the UIApplication class.

您可以尝试结合区域监控,在 didEnterEter 区域进行服务器调用,然后调用 beginBackgroundTaskWithName:expirationHandler: 以确保您有足够的时间。不过,区域监控+服务器调用+后台处理的组合会影响电池生命周期。

编辑:您还可以创建包含许多较小区域的大区域的“大型区域”。当用户进入那些大型区域时,设置并添加您感兴趣的所有较小区域,当他们退出时,将它们移除。

关于iOS区域监控,监控20多个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153928/

相关文章:

ios - 第一次加载应用程序时,MKMapview ios 不显示当前位置

ios - 如何在服务器上聚合 iOS 位置数据?

ios - 将 Xamarin.Forms 应用程序部署到物理 iOS 设备时出现 "resource fork, Finder information, or similar detritus not allowed"错误

ios - info plist 似乎已过时,无法通过 App Store 验证 App

ios - SKPhysicsBody 减速程序

android - OSMDROID:使用osmdroid map 实时获取当前坐标

java - Android 转弯 API?

ios - 在 iOS 中获取字符串中空格后的字符

android - 提取GPS信息到 "steady"和 "Moving"

c++ - 我应该把第三方库放在哪里?