【问题标题】:iOS App working with BLE mini与 BLE mini 配合使用的 iOS 应用程序
【发布时间】:2014-06-17 08:53:58
【问题描述】:

我已将我的 iOS 应用程序连接到一个 BLE Mini 并且它到达了didDiscoverCharacteristics 方法。

我对这里应该发生的事情有点困惑。我发现的几个示例使用 for 循环来遍历特征,并在找到正确的特征时执行某些操作。有没有办法找到特征的特定ID?

【问题讨论】:

标签: ios methods bluetooth bluetooth-lowenergy core-bluetooth


【解决方案1】:

您应该使用CBCentralManager 并实现CBCentralManagerDelegate

然后,在didDiscoverPeripheral: 方法中检查CBPeripheral 对象,检查它是否是您正在寻找的对象并执行您的工作。

实施

  1. 声明一个属性。

    @property(nonatomic, strong) CBCentralManager *centralManager;
    
  2. 创建一个CBCentralManager

    _centralManager = [[CBCentralManager alloc] initWithDelegate:self
                                                           queue:nil];
    
  3. 实现CBCentralManagerDelegate 协议。

    - (void)centralManagerDidUpdateState:(CBCentralManager *)centralManager
    {
        if (centralManager.state == CBCentralManagerStatePoweredOn)
        {
            NSLog(@"Start scanning");
    
            // This will scan for all peripherals.
            [_centralManager scanForPeripheralsWithServices:nil
                                                    options:nil];
        }
    }
    
    - (void)centralManager:(CBCentralManager *)central
     didDiscoverPeripheral:(CBPeripheral *)peripheral
         advertisementData:(NSDictionary *)advertisementData
                      RSSI:(NSNumber *)RSSI
    {
        NSLog(@"Peripheral: %@", peripheral);
    
        // Do stuff.
    }
    

祝你好运。

【讨论】:

    猜你喜欢
    • 2012-02-01
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 2013-10-29
    • 2012-03-06
    相关资源
    最近更新 更多