iOS可以构建一个应用程序或服务来保持蓝牙发现设备

时间:2012-09-07 02:23:56

标签: ios bluetooth push-notification bluetooth-lowenergy

如果发现新设备,则将通知推送给用户。 如何开始和任何资源/示例代码?

1 个答案:

答案 0 :(得分:2)

前三个答案都不正确。 iOS5引入了Core Bluetooth framework

然而,此框架仅限BT 4.0 LE ;毫无疑问的蓝牙。

这里也是PDF参考:http://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CoreBluetooth_Framework/CoreBluetooth_Framework.pdf

实施例

您的课程必须符合 CBCentralManagerDelegate CBPeripheralDelegate 协议。

CBCentralManager * btCentral = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

/* Create an array of services from a CBUUID to scan for */
[btCentral scanForPeripheralsWithServices:nil options:nil];

这基本上是为了让您开始扫描外围设备。您还需要实施 CBCentralManagerDelegate 方法和其他一些方法,我建议您阅读文档:

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals