【发布时间】:2014-02-04 05:57:12
【问题描述】:
我想用我的ipad蓝牙模拟多个ibeacon信号,可以吗
【问题讨论】:
标签: ios bluetooth-lowenergy ibeacon
我想用我的ipad蓝牙模拟多个ibeacon信号,可以吗
【问题讨论】:
标签: ios bluetooth-lowenergy ibeacon
您不能同时进行多个传输,但您可以通过在两个或多个带有计时器的发射器之间切换来模拟这一点。 iOS 设备在作为 iBeacon 传输时通常每秒发送 10 个广告数据包。但是接收者只希望在正常操作中至少每秒接收一次数据包。
尝试设置一个计时器以在两个 iBeacon 发射器之间来回切换(关闭一个,然后打开另一个)。像这样:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"We are going to simulate advertising multiple iBeacons simultaneously!");
CLBeaconRegion *iBeacon1 = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] major:15555 minor:35001 identifier:@"iBeacon1"];
CLBeaconRegion *iBeacon2 = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] major:15555 minor:35002 identifier:@"iBeacon2"];
iBeacons = [[NSMutableArray alloc] init];
[iBeacons addObject: iBeacon1];
[iBeacons addObject: iBeacon2];
measuredPower = [NSNumber numberWithInt:-59];
currentIBeaconNumber = 0;
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
[self rotateAdvertising];
return YES;
}
- (void) configureAdvertisingForIBeaconNumber: (int) iBeaconNumber {
if(self.peripheralManager.state!=CBCentralManagerStatePoweredOn) {
NSLog(@"Core Bluetooth is off");
return;
}
[self.peripheralManager stopAdvertising];
NSLog(@"Transmitting as iBeacon number %d", currentIBeaconNumber);
NSDictionary *peripheralData;
peripheralData = [[iBeacons objectAtIndex:iBeaconNumber] peripheralDataWithMeasuredPower:measuredPower];
[self.peripheralManager startAdvertising:peripheralData];
}
- (void) rotateAdvertising {
[self configureAdvertisingForIBeaconNumber:currentIBeaconNumber];
currentIBeaconNumber = (currentIBeaconNumber + 1) % iBeacons.count;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1000* NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
[self rotateAdvertising];
});
}
我对此进行了测试,它可以工作——第二台 iOS 设备同时安装了两个 iBeacon。
如果我尝试在两个标识符之间切换超过每秒一次,接收 iOS 设备将定期丢失对其中一个信标的跟踪。由于此代码每秒仅切换一次,因此接收器在不接收两个 iBeacon 传输之一时将有超过一秒的间隙。这可能会也可能不会对接收器端的测距/监控造成一些意想不到的副作用。但是你可以试试看。
【讨论】:
[beacons count] > 1?