简体   繁体   English

iOS-关闭WiFi的地理围栏

[英]iOS - Geofencing with WiFi turned off

I have code that creates a geofence on my iPhone that will trigger some code to be executed when didExitRegion gets called. 我有在iPhone上创建地理围栏的代码,当didExitRegion被调用时,它将触发一些代码被执行。 However, I have found that when I have WiFi switched off that didExitRegion never gets triggered. 但是,我发现当我关闭WiFi时,didExitRegion永远不会触发。 Is WiFi required for monitoring region changes on iOS? 在iOS上监视区域更改是否需要WiFi? My desired accuracy is set to kCLLocationAccuracyHundredMeters. 我想要的精度设置为kCLLocationAccuracyHundredMeters。 I am testing on iOS 6.1 and iPhone 4. 我正在iOS 6.1和iPhone 4上进行测试。

Here is my code for setting up location monitoring: 这是我用于设置位置监控的代码:

- (id)init {
self = [super init];
if (self) {
    CLLocationManager *manager = [[CLLocationManager alloc] init];
    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    manager.distanceFilter = RADIUS/10.0;
    manager.headingFilter = kCLHeadingFilterNone;
    self.locationManager = manager;
    self.authorizationStatus = [CLLocationManager authorizationStatus];
}
return self;
}

Thanks 谢谢

iOS devices use three methods to discover user location. iOS设备使用三种方法来发现用户位置。 From (usually) most accurate to least accurate they are: 从(通常)最准确到最不准确,它们是:

  1. GPS hardware GPS硬件
  2. By identifying nearby wifi networks 通过识别附近的wifi网络
  3. Cell Tower Triangulation 细胞塔三角剖分

If your app doesn't use GPS or is not running (ie. has previously been terminated), the device will attempt to use methods 2 and 3 above to locate the user. 如果您的应用未使用GPS或未运行(即先前已终止),则设备将尝试使用上述方法2和3来找到用户。 So the device's ability to locate the user (when the GPS hardware is not in use or there is a weak GPS signal) depends on the availability of wifi networks and cell towers. 因此,设备定位用户的能力(当不使用GPS硬件或GPS信号较弱时)取决于wifi网络和基站的可用性。 The more wifi networks and cell towers, the better the location accuracy. wifi网络和手机信号塔越多,位置精度越高。 Therefore, when a user enters or exits a monitored region (ie. crosses a "geofence"), it is impossible to predict exactly when the user will receive the notification if at all. 因此,当用户进入或离开监视区域(即越过“地理范围”)时,根本无法准确预测用户何时将收到通知。 (Of course, if the region in question is always the same, the device will more or less locate the user with the same degree of accuracy on each occasion). (当然,如果所讨论的区域始终相同,则设备将在每种情况下或多或少以相同的精确度定位用户)。

Here's the relevant documentation from the Location Awareness Programming Guide : 以下是《 位置感知编程指南》中的相关文档:

The specific threshold distances are determined by the hardware and the location technologies that are currently available. 特定的阈值距离由当前可用的硬件和定位技术确定。 For example, if Wi-Fi is disabled, region monitoring is significantly less accurate. 例如,如果禁用了Wi-Fi,则区域监视的准确性会大大降低。 However, for testing purposes, you can assume that the minimum distance is approximately 200 meters. 但是,出于测试目的,您可以假定最小距离约为200米。

So, wifi is not required for region monitoring to work, but with it enabled, your device will have a better chance in determining whether or not the user has crossed a region's geofence. 因此,不需要wifi即可运行区域监视,但是启用该功能后,您的设备将更有机会确定用户是否越过区域地理围栏。

If you turn off WiFi, your location accuracy lowers. 如果关闭WiFi,则位置精度会降低。 If you don't have GPS signal(inside some buildings), you will not get any location updates. 如果没有GPS信号(在某些建筑物内),则不会获得任何位置更新。 Have you tried this when you are outside, or if you used the location simulator to test? 您是否在室外或尝试使用位置模拟器进行测试?

Also, WiFI is not required for geofence function if you have GPS(iPhones or iPad with sims). 此外,如果您具有GPS(iPhone或带SIM卡的iPad),则地理围栏功能也不需要WiFI。

Weird weird stuff can happen without wifi using core location. 没有使用核心位置的wifi,可能会发生奇怪的奇怪事情。 To help in your case I would get rid of the distance filter, that can mess with things and it is not very helpful. 为了给您提供帮助,我将摆脱距离过滤器,它可能会使事情变得混乱,并且不是很有帮助。 I would probably only use kCLLocationAccuracyBest for anything where I need the accuracy required to set up a geofence. 我可能只将kCLLocationAccuracyBest用于需要设置地理围栏所需的精度的任何事情。 Using other accuracies and filters for me would sometimes through the gps meter off by 1000 meters and take a minute or two to correct itself. 对我来说,使用其他精度和过滤器有时会使gps仪表偏离1000米,并且需要一到两分钟来纠正自身。 If this is too much battery then set up a system where it turns off and on based on how far away it is from the fence. 如果这是过多的电池,则根据离栅栏的距离,设置一个关闭并重新打开的系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM