尝试设置一个定时器在两个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传输之一时,接收器将具有略超过一秒的间隙.这可能会或可能不会对接收器侧的测距/监测造成一些意外的副作用.但是你可以尝试看看.
总结以上是内存溢出为你收集整理的ios – 我可以只从一个蓝牙广播多个ibeacon信号吗?如何全部内容,希望文章能够帮你解决ios – 我可以只从一个蓝牙广播多个ibeacon信号吗?如何所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)