ios - 我可以只从一个蓝牙广播多个 ibeacon 信号吗?如何

标签 ios bluetooth-lowenergy ibeacon

我想用ipad的蓝牙模拟多个ibeacon信号,可以吗

最佳答案

你不能让多个传输同时发出,但你可以通过使用定时器在两个或多个发射器之间切换来模拟这一点。当作为 iBeacon 传输时,iOS 设备通常每秒发送 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 传输之一时会有一秒多一点的间隙。这可能会也可能不会对接收器端的测距/监控造成一些意想不到的副作用。但是你可以试试看。

关于ios - 我可以只从一个蓝牙广播多个 ibeacon 信号吗?如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21545005/

相关文章:

ios - 如何通过滑动手势改变分段控件的值?

ios - TableView Reloaddata 在编辑更改值时不起作用

ios7 - 低功耗蓝牙 (IOS) - 后台广告和自定义广告数据

android - 估计 iBeacon : Monitoring in background (Android)

ios - 创建一个城市和州的字典,以便在 UITableView 中存储一个字符串

ios - iPad 上未显示应用程序图标

java - 蓝牙低功耗安全异常

ios - didDisconnectPeripheral 自己调用

bluetooth-lowenergy - 禁用 LE Set Scan Enable 命令的 "Filter duplicates"设置

bluetooth-lowenergy - 我应该在 iBeacon 中使用 MacAdress 还是 UUID