iOS iBeacon基本操作
示例
设置监控信标
func initiateRegion(ref:BeaconHandler){
let uuid: NSUUID = NSUUID(UUIDString: "<UUID>")
let beacon = CLBeaconRegion(proximityUUID: uuid, identifier: "")
locationManager?.requestAlwaysAuthorization() //分区管理器对象
beacon?.notifyOnEntry = true
beacon?.notifyOnExit = true
beacon?.notifyEntryStateOnDisplay = true
locationManager?.startMonitoringForRegion(beacon!)
locationManager?.delegate = self;
//检查信标监视是否可用于此设备
if (!CLLocationManager.isMonitoringAvailableForClass(CLBeaconRegion)) {
print("error")
}
locationManager!.startRangingBeaconsInRegion(self.beacon!)
}位置经理进入和退出区域
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
if(region.isKindOfClass(CLBeaconRegion)) {
locationManager!.startRangingBeaconsInRegion(self.beacon!)
}
}
func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
if(region.isKindOfClass(CLBeaconRegion)) {
locationManager!.stopRangingBeaconsInRegion(self.beacon!)
}
}位置管理器范围信标
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
print(beacons.first.major)
}
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短