【问题标题】:search and connect bluetooth device from iPhone app从 iPhone 应用程序搜索和连接蓝牙设备
【发布时间】:2016-08-16 09:07:50
【问题描述】:

我正在尝试通过我的 APP 使用 iPhone/iPad 设备的蓝牙,并在范围内搜索附近的设备并连接到该设备。

与范围内的非 iOS 手机或 MAC 一样,它应该显示可用设备以及何时需要从应用程序连接。

我想从我的应用程序中执行此操作。 我使用核心蓝牙框架尝试了以下代码:

    _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 手机(蓝牙 4.0 LE 兼容)。 scanForPeripheralsWithServices:nil 我设置 nil 以显示所有可用设备....

提前致谢。

【问题讨论】:

  • 你能添加你想要实现这个的 ios 版本吗?
  • 最新...基本上我想通过蓝牙从 iPhone 连接到 RFID 阅读器...所以首先我正在寻找蓝牙连接...

标签: ios objective-c core-bluetooth


【解决方案1】:

您必须使用 [CBPeripheralManager]

设置委托后,触发 [scanForPeripheralsWithServices:options:] 然后在委托方法 [didDiscoverPeripheral] 中,您将获得每个外围设备的名称。然后您可以向用户显示可用设备列表,然后使用 CBCentralManager 中的功能 connectPeripheral

您可以找到用 Objective-C here 编写的精彩教程。

【讨论】:

  • 您好,您提到了CoreBluetooth 框架。此框架仅允许连接低功耗蓝牙设备。你能打电话给我吗?我必须有一个应用程序,它通常需要连接附近所有可用的设备……因为我用谷歌搜索它是不可能的。是真的还是有办法……我们可以做到这一点?
  • 没有这样的框架可以让你做到这一点。据我所知,CB 框架是 Apple 唯一接受的库。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多