iOS Region Monitoring not working

白昼怎懂夜的黑 提交于 2019-12-06 14:21:26

Please ensure [CLLocationManager regionMonitoringAvailable] returns YES and CLLocationManager.monitoredRegions contains valid regions.

Also, from Apple documentation:

In iOS 6, regions with a radius between 1 and 400 meters work better on iPhone 4S or later devices. (In iOS 5, regions with a radius between 1 and 150 meters work better on iPhone 4S and later devices.) On these devices, an app can expect to receive the appropriate region entered or region exited notification within 3 to 5 minutes on average, if not sooner.

And

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

I ended up using the CLRegion.containsCoordinate(location.coordinate) method instead. It works pretty much the same way.

Once the object has entered my set region, it returns true and from here I can know when it's entered and exited the region.

There are many causes why your delegates are not triggering. First goto target settings and in capabilities tab check whether in BackgroundModes Location Updates is enabled. If it is on then try to check whether your current location manager holds the region you've specified by checking NSLog(@"Monitored Regions %@",self.locationManager.monitoredRegions);

Then if the user device is at current location(Latitude and longitude) the didEnterRegion: and didExitRegion: delegates will not be triggering. Use didDetermineState: method to find whether the user/device is in current region that is moniotred. If it so, didDetermineState: will be triggered. Once the user leaves the region didExitRegion: will be triggered.

Then after also if delegates aren't trigerring then find then error using the following in delegate - (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error { NSLog(@"Failed to Monitor %@", error); }

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