search and connect bluetooth device from iPhone app
我正在尝试从我的APP中使用iPhone / iPad设备的蓝牙,并搜索范围内的设备附近并连接至该设备。
与非iOS手机或MAC在范围内一样,它应显示可用设备以及何时需要从应用程序连接水龙头。
我想通过我的应用程序执行此操作。
我已经使用核心蓝牙框架尝试了以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 | _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; _centralManager.delegate = self; - (void)DidUpdateState:(CBCentralManager *)central { if (central.state != CBCentralManagerStatePoweredOn) { return; } //start scanning [self.centralManager scanForPeripheralsWithServices:nil options:nil]; } |
但没有代表被叫...我正在iPad 4上运行应用程序,并且我拥有LE android手机(兼容Bluetooth 4.0 LE)。
scanForPeripheralsWithServices:nil我将nil设置为显示所有可用的设备...。
非常感谢。
您将必须使用[CBPeripheralManager]。
设置委托后,启动[scanForPeripheralsWithServices:options:],然后在委托方法[didDiscoverPeripheral]中为每个外围设备获取一个名称。然后,您可以向用户显示可用设备的列表,然后在CBCentralManager中使用函数connectPeripheral。
您可以在这里找到用Objective-C编写的出色教程。