信标/ IOS CLLocationManager获取当前区域 [英] Beacon / IOS CLLocationManager get current region

查看:164
本文介绍了信标/ IOS CLLocationManager获取当前区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个正在寻找信标的程序,我实现了CLLocationManager,并且我的应用程序除一点以外都可以运行。
我打电话给startMonitoringForRegion()来获取didEnterRegion / didExitRegion回调。在这些函数中,我正在执行startRangingBeaconsInRegion()/ stopRangingBeaconsInRegion(),以便在用户位于信标区域时获得准确的信息。
我的问题很简单,如果在用户已经处于信标范围内时启动应用程序,则不会调用didEnterRegion。

I'm doing a program who is looking for beacon, I implemented CLLocationManager and my apps works except one point. I'm calling startMonitoringForRegion() in order to get the didEnterRegion/didExitRegion callback. Inside these function I'm doing startRangingBeaconsInRegion()/stopRangingBeaconsInRegion() in order to get precise information when the user is in the beacon area. My issue is quite simple, if the app is started when the user is already in the beacon range, didEnterRegion is not called.

我在寻找像isInRegion()这样的函数,以便在我的应用程序启动时可以执行startMonitoringForRegion(),然后执行isInRegion()和startRangingBeaconsInRegion()(如果用户已经在该区域中)。

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.

我当前的解决方法是在应用启动时调用startRangingBeaconsInRegion(),然后在didRangeBeacons回调中,如果未找到信标,我将在stopRangingBeaconsInRegion()中进行操作。
我不认为这是一种非常干净的方法,如果可能的话,希望用更好的东西代替

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. I don't think that it's a very clean way and would like to replace by something better if possible

谢谢,

推荐答案

您可以使用 locationManager:didDetermineState:forRegion:回调,它告诉您是否是内部外部未知

You can use the locationManager:didDetermineState:forRegion: callback, which tells you if you are either Inside, Outside or Unknown.

您可以通过以下方式强制自己进行回调:

You can force yourself to get a callback by calling

locationManager.requestStateForRegion(region)

应用启动时。

请参阅此处更多内容: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/#//apple_ref/occ/intfm/CLLocationManagerDelegate/locationManager :didDetermineState:forRegion

See more here: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/#//apple_ref/occ/intfm/CLLocationManagerDelegate/locationManager:didDetermineState:forRegion:

这篇关于信标/ IOS CLLocationManager获取当前区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆