我正在与iBeacons合作。我有多个信标,每个信标具有相同的UUID,主要但不同的次要值。这两种设备都是远程设备,但它们不是一起接收的 - locationManager:didRangeBeacons:inRegion:委托回调" beacons"数组一次只包含1个信标。
我知道使用多个区域会分别进行回调
这是用于监视和测距信标的代码
// Initialize and monitor regions
for (NSString *serviceUUID in _serviceUUIDs) {
// Initialize region
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:serviceUUID];
CLBeaconRegion *appBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:minor identifier:identifier];
// Specify notifications
appBeaconRegion.notifyEntryStateOnDisplay = YES;
appBeaconRegion.notifyOnEntry = YES;
appBeaconRegion.notifyOnExit = YES;
// Add to regions
[_appBeaconRegions addObject:appBeaconRegion];
// Begin monitoring region and ranging beacons
[_locationManager startMonitoringForRegion:appBeaconRegion];
[_locationManager startRangingBeaconsInRegion:appBeaconRegion];
}
我想拥有一个回调范围内的所有信标
如何使用具有所有信标的不同次要标识符值的单个区域
任何帮助表示赞赏..
由于
答案 0 :(得分:0)
这是我为此目的编写的代码: -
// in ApplicationdidFinishLaunchingWithOptions
let beaconID = NSUUID(UUIDString: "ADBD15B8-9A2F-492F-BB26-C7C92E05CAD3")
let regionIdentifier = "humra.ibeacons"
let beaconRegion = CLBeaconRegion(proximityUUID: beaconID!, identifier: regionIdentifier)
if locationManager.respondsToSelector("requestAlwaysAuthorization")
{
locationManager.requestAlwaysAuthorization()
}
locationManager.delegate=self
locationManager.pausesLocationUpdatesAutomatically=false
locationManager.startMonitoringForRegion(beaconRegion)
locationManager.startRangingBeaconsInRegion(beaconRegion)
locationManager.startUpdatingLocation()
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
NSLog("didRangeBeacons");
let message:String = ""
if(beacons.count > 0) {
let nearestBeacon:CLBeacon = beacons[0] as CLBeacon
closestBeacon=nearestBeacon
} else {
// message = "No beacons are nearby"
}
NSLog("%@", message)
sendLocalNotificationWithMessage(message)
}