简体   繁体   English

信标/ IOS CLLocationManager获取当前区域

[英]Beacon / IOS CLLocationManager get current region

I'm doing a program who is looking for beacon, I implemented CLLocationManager and my apps works except one point. 我正在做一个正在寻找信标的程序,我实现了CLLocationManager,并且我的应用程序除一点外都可以运行。 I'm calling startMonitoringForRegion() in order to get the didEnterRegion/didExitRegion callback. 我正在调用startMonitoringForRegion()以获取didEnterRegion / didExitRegion回调。 Inside these function I'm doing startRangingBeaconsInRegion()/stopRangingBeaconsInRegion() in order to get precise information when the user is in the beacon area. 在这些函数中,我正在执行startRangingBeaconsInRegion()/ stopRangingBeaconsInRegion(),以便在用户位于信标区域时获得准确的信息。 My issue is quite simple, if the app is started when the user is already in the beacon range, didEnterRegion is not called. 我的问题很简单,如果在用户已经处于信标范围内时启动应用程序,则不会调用didEnterRegion。

I'm looking for a function like isInRegion() so that when my app start I could do startMonitoringForRegion() then isInRegion() and startRangingBeaconsInRegion() if the user is already in the region. 我正在寻找isInRegion()之类的功能,以便在我的应用启动时可以先执行startMonitoringForRegion(),然后再执行isInRegion()和startRangingBeaconsInRegion()(如果用户已经在该区域中)。

My current workaround is to call startRangingBeaconsInRegion() when the app start, then in the didRangeBeacons callback, I'm doing stopRangingBeaconsInRegion() if no beacon is found. 我当前的解决方法是在应用启动时调用startRangingBeaconsInRegion(),然后在didRangeBeacons回调中,如果未找到信标,则在执行stopRangingBeaconsInRegion()。 I don't think that it's a very clean way and would like to replace by something better if possible 我认为这不是一种很干净的方法,如果可能的话,我想用更好的方法代替

Thanks, 谢谢,

You can use the locationManager:didDetermineState:forRegion: callback, which tells you if you are either Inside , Outside or Unknown . 您可以使用locationManager:didDetermineState:forRegion:回调,它告诉您是InsideOutside还是Unknown

You can force yourself to get a callback by calling 您可以通过致电强制自己进行回调

locationManager.requestStateForRegion(region)

when your app starts up. 当您的应用启动时。

See more here: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/#//apple_ref/occ/intfm/CLLocationManagerDelegate/locationManager:didDetermineState:forRegion : 在此处查看更多信息: https : //developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/#//apple_ref/occ/intfm/CLLocationManagerDelegate/locationManager :didDetermineState: forRegion

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

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