iOS - Geofencing with WiFi turned off

二次信任 提交于 2019-12-04 12:00:57

问题


I have code that creates a geofence on my iPhone that will trigger some code to be executed when didExitRegion gets called. However, I have found that when I have WiFi switched off that didExitRegion never gets triggered. Is WiFi required for monitoring region changes on iOS? My desired accuracy is set to kCLLocationAccuracyHundredMeters. I am testing on iOS 6.1 and 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


回答1:


iOS devices use three methods to discover user location. From (usually) most accurate to least accurate they are:

  1. GPS hardware
  2. By identifying nearby wifi networks
  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. 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. The more wifi networks and cell towers, the better the location accuracy. 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. However, for testing purposes, you can assume that the minimum distance is approximately 200 meters.

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.




回答2:


If you turn off WiFi, your location accuracy lowers. If you don't have GPS signal(inside some buildings), you will not get any location updates. 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).




回答3:


Weird weird stuff can happen without wifi using core location. 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. 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. 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.



来源:https://stackoverflow.com/questions/15884330/ios-geofencing-with-wifi-turned-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!