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

 mobiledu2502882453 发布于 2023-01-29 15:32

我想用ipad的蓝牙模拟多个ibeacon信号,是否可能

1 个回答
  • 您不能同时进行多个传输,但您可以通过使用计时器在两个或更多个发送器之间切换来模拟这种情况.当作为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设备包括两个iBeacons.

    如果我尝试每秒多次在两个标识符之间切换,则接收iOS设备会定期丢失其中一个信标.因为这个代码仅每秒切换一次,接收机将有超过一个第二一点点的间隙时它不会被接收两个iBeacon显示变速器中的一个.这可能会或可能不会对接收器侧的测距/监测造成一些意外的副作用.但是你可以尝试看看.

    2023-01-29 15:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有