本文介绍了我可以只从一个蓝牙广播多个ibeacon信号吗?如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to simulate multiple ibeacon signal using my ipad's bluetooth, is it possible

推荐答案

你不能让多个传输出去同时,但您可以通过使用计时器在两个或更多发射器之间切换来模拟这一点。当作为iBeacon进行传输时,iOS设备通常每秒发送10个广告包。但是接收器只希望在正常操作时每秒至少接收一次数据包。

You cannot make multiple transmissions go out simultaneously, but you can simulate this by switching between two or more transmitters with a timer. iOS devices normally send out 10 advertising packets per second when transmitting as an iBeacon. But receivers only expect that packets be received at a minimum of once every second for normal operations.

尝试设置定时器在两个iBeacon发送器之间来回切换(转向一个然后另一个)。像这样:

Try setting up a timer to switch back and forth between two iBeacon transmitters (turn one off then the other on). Like this:

    - (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。

I tested this and it works -- a second iOS device ranged both iBeacons.

如果我试图每秒多次在两个标识符之间切换,接收iOS设备会定期丢失其中一个信标。因为此代码每秒仅切换一次,所以当接收器不接收两个iBeacon传输中的一个时,接收器将具有略超过一秒的间隙。这可能会或可能不会对接收器侧的测距/监测造成一些意外的副作用。但你可以尝试看看。

If I tried to switch between the two identifiers more than once per second, the receiving iOS device would periodically lose track of one of the beacons. Because this code is only switching once per second, the receiver will have gaps of a little over one second when it won't be receiving one of the two iBeacon transmissions. This may or may not cause some unexpected side effects on ranging/monitoring on the receiver side. But you can try it and see.

这篇关于我可以只从一个蓝牙广播多个ibeacon信号吗?如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 09:04