你能建议在iOS上发现任何蓝牙设备吗?

时间:2014-10-13 10:41:56

标签: ios bluetooth

我尝试制作程序来检测iOS上不确定的蓝牙设备。

设备扫描工作正常,但无法检测到任何设备。然而,在Ipad的基本选项中,蓝牙设备被很好地检测到了。贝娄显示我的代码。请指教解决一些问题。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //CB setup
    _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    // You should test all scenarios
    if (central.state != CBCentralManagerStatePoweredOn) {
        return;
    }

    if (central.state == CBCentralManagerStatePoweredOn) {
        _scan_state = 1;
    }

    [self deviceScan];

}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
    NSLog(@"dicovered: %@", peripheral.name);

    if(![self.BTNames containsObject:peripheral]){
        [self.BTNames addObject:peripheral];
    }


    _num_cell = self.BTNames.count;

    [self.BTList reloadData];

}

- (void) deviceScan{
    if(_scan_state){
/*        [_centralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @NO }];*/
        [_centralManager scanForPeripheralsWithServices:nil options:nil];
        NSLog(@"Scan Starting");
    }
}

0 个答案:

没有答案