简体   繁体   English

核心蓝牙:无法让iPhone(中央)和Mac(外围设备)配对

[英]Core Bluetooth: Cannot get iPhone (the central) and Mac (the peripheral) to pair

I am developing an iPhone application and a Mac application that communicate with each other via Bluetooth LE. 我正在开发一个iPhone应用程序和一个通过蓝牙LE相互通信的Mac应用程序。 The iPhone is the central, and the Mac is the peripheral. iPhone是核心,Mac是外围设备。 I would like the iPhone application to be able to reconnect to the Mac application after a relaunch. 我希望iPhone应用程序能够在重新启动后重新连接到Mac应用程序。 Therefore, I save the UUID of the peripheral representing the Mac in NSUserDefaults, and then when the iPhone app launches, I call -[CBCentralManager retrievePeripheralsWithIdentifiers:] , passing in the UUID. 因此,我在NSUserDefaults中保存代表Mac的外围设备的UUID,然后当iPhone应用程序启动时,我调用-[CBCentralManager retrievePeripheralsWithIdentifiers:] ,传入UUID。 Although this method returns the peripheral, when I call -[CBCentralManager connectPeripheral:options:] , the iPhone never reconnects to the Mac. 虽然这种方法返回外设,但当我调用-[CBCentralManager connectPeripheral:options:] ,iPhone永远不会重新连接到Mac。 According to this SO post, the problem is that the two devices need to be paired so that the UUID of the Mac is persistent. 根据这篇 SO帖子,问题是这两个设备需要配对,以便Mac的UUID是持久的。 This brings me to my problem. 这让我想到了我的问题。 I cannot for the life of me get the iPhone and the Mac to pair. 我不能为我的生活让iPhone和Mac配对。 According to this page of the Core Bluetooth Programming Guide, the way to require a paired connection is for the peripheral to set the characteristic's properties and permissions to the appropriate values. 根据“核心蓝牙编程指南”的页面,要求配对连接的方法是外围设备将特性的属性和权限设置为适当的值。 I quote: 我引用:

You can ensure that only trusted devices have access to sensitive characteristic values by setting the appropriate characteristic properties and permissions. 您可以通过设置适当的特性属性和权限,确保只有受信任的设备才能访问敏感的特征值。 To continue the example above, to allow only trusted devices to retrieve a member's email address, set the appropriate characteristic's properties and permissions, like this: 要继续上面的示例,要仅允许受信任的设备检索成员的电子邮件地址,请设置相应的特性的属性和权限,如下所示:

emailCharacteristic = [[CBMutableCharacteristic alloc]
    initWithType:emailCharacteristicUUID
    properties:CBCharacteristicPropertyRead
    | CBCharacteristicPropertyNotifyEncryptionRequired
    value:nil permissions:CBAttributePermissionsReadEncryptionRequired];

However, this does not work. 但是, 这不起作用。 Even when I set the correct permissions and properties for the characteristic, the iPhone can still read/write to it without a pairing dialog being displayed. 即使我为特征设置了正确的权限和属性,iPhone仍然可以读取/写入它而不显示配对对话框。 Elsewhere I am told that the way to initiate pairing is for the peripheral to reject a read/write request with an insufficient authentication error. 在其他地方我被告知启动配对的方法是外围设备拒绝认证错误不足的读/写请求。 According to this post, 根据这篇文章,

To pair, you need to respond to a write request with an insufficient authentication error. 要配对,您需要响应认证错误不足的写入请求。 For example, for an iOS peripheral you would write something like: 例如,对于iOS外围设备,您可以编写如下内容:

- (void)peripheralManager:(CBPeripheralManager *)peripheralManager didReceiveWriteRequests:(NSArray *)requests {
  ...

  [peripheralManager respondToRequest:request withResult:CBATTErrorInsufficientAuthentication];

  ...
}

But this still doesn't work! 但这仍然不起作用! When the Mac rejects the write request with an insufficient authentication error, the iPhone receives a -[CBPeripheralDelegate peripheral:didWriteValueForCharacteristic:error:] callback with an error that says, "Authentication is insufficient." 当Mac拒绝认证错误的写入请求时,iPhone会收到-[CBPeripheralDelegate peripheral:didWriteValueForCharacteristic:error:]回调,并显示“身份验证不足”的错误。 No pairing dialog. 没有配对对话框。 I have no idea what to do and am considering dropping Core Bluetooth altogether if I cannot get this to work. 我不知道该怎么办,如果我不能让它工作,我正在考虑完全放弃Core Bluetooth。 If you have any idea how to get this to work, please let me know. 如果您有任何想法如何工作,请告诉我。

From Apple DTS: "I have checked with other engineers here and we don't believe that the pairing popup is possible between two iOS devices, but an iOS device and a BLE peripheral." 来自Apple DTS:“我已经在这里与其他工程师进行了核实,我们不相信两个iOS设备之间可以配对弹出,而是iOS设备和BLE外围设备。”

So, pairing popup happens only between a iOS/Mac app and a peripheral. 因此,配对弹出窗口仅在iOS / Mac应用程序和外围设备之间发生。 rdar time. 时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用核心蓝牙框架将Mac mini设置为外围设备 - Set mac mini as a peripheral device using core bluetooth framework 使用Core Bluetooth在后台获取蓝牙LE外围设备广告 - Using Core Bluetooth to get Bluetooth LE peripheral advertisements in background 核心蓝牙:从外围端发布了一些字符,但只能从中央端接收制造商名称字符串 - Core Bluetooth: published some character from peripheral side but only be able to receive Manufacturer Name String frrom central side iOS Core蓝牙外围设备连接请求 - IOS Core bluetooth peripheral connection request iOS核心蓝牙不要求配对 - iOS Core Bluetooth Not asking for Pair iPhone是外围设备还是中央设备,可以一个接一个地连接到几个外围设备上吗? - Is an iPhone being peripheral and central with connecting to several peripheral iPhones one after another doable? 我可以将BLE设备(也许是Mac上的一个应用程序)与iPhone蓝牙配对,而没有手机上的应用程序 - can I have a BLE device (maybe an app on mac) pair with iphone bluetooth without an app on the phone 如何以编程方式获取iPhone的蓝牙MAC地址? - How can I programmatically get the Bluetooth MAC address of an iPhone? Mac和iPhone之间的蓝牙通信 - Bluetooth communication between Mac and iPhone iOS蓝牙:中央外围设备在接受配对请求之前已连接 - iOS Bluetooth: central- peripheral got connected before accepting pairing request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM