我想通过使用estimote信标通知用户他/她到达特定楼层。为了完成我的任务,我开发了如下代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.beaconManager.delegate = self
self.beaconManager.requestAlwaysAuthorization()
let firstFloorRegion = CLBeaconRegion(
proximityUUID: uuid,
major: 2, identifier: "")
firstFloorRegion.notifyOnEntry = true
firstFloorRegion.notifyOnExit = true
firstFloorRegion.notifyEntryStateOnDisplay = true
self.beaconManager.startMonitoring(for: firstFloorRegion)
self.beaconManager.requestState(for: firstFloorRegion)
return true
}
func beaconManager(manager: AnyObject, didDetermineState region: CLBeaconRegion) {
NSLog("didDetermineState Called")
}
private func beaconManager(manager: AnyObject, didEnterRegion region: CLBeaconRegion) {
NSLog("DidEnterRegion Called")
}
private func beaconManager(manager: AnyObject, didExitRegion region: CLBeaconRegion) {
NSLog("didExitRegion Called")
}
几天它完美无缺。但是从最近2天开始,它在xcode控制台中显示错误,如下所示:
[客户] {" msg":" Fence:onClientEventRegionState,无效状态"," regionState":" 0" }
我无法理解它的含义。我也没有在互联网上找到任何解决方案。帮助我摆脱它。
答案 0 :(得分:3)
我注意到手机重启后iBeacon监控(以及一般的区域监控)最多需要10分钟才能工作。果然,当我打电话
时,我重新启动手机并在控制台输出中出现错误manager.requestState(for: myRegion)
我从未见过Apple谈论调用
的任何负面影响manager.startMonitoring(for: myRegion)
已经注册的地区。但是,每次应用程序启动时我都不会调用它。相反,我检查这样的监控区域:
for monitoredRegion in self.locationManager.monitoredRegions as! Set<CLBeaconRegion> {
print("Monitoring: " + monitoredRegion.proximityUUID.uuidString + " " + monitoredRegion.identifier)
self.locationManager.requestState(for: monitoredRegion)
switch monitoredRegion.proximityUUID.uuidString {
case myRegionUUID.uuidString:
needToMonitorMyRegion = false
default:
break
}
}
当我验证这样的注册时,我没有收到错误。我只在手机重启时发现错误。