如何在Swift Xcode中以编程方式绑定/配对到蓝牙LE设备? [英] How to bond/pair to a bluetooth LE device programmatically in swift Xcode?

查看:87
本文介绍了如何在Swift Xcode中以编程方式绑定/配对到蓝牙LE设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试开发和应用程序,允许用户通过单击按钮将其绑定到外围设备,并且密码将被自动输入.

I am currently trying to develop and application that allows users to bond to a Peripheral via a click of a button and the password will be automatically entered.

是否可以使用swift以编程方式绑定和删除绑定?

Is it possible to Bond and Remove Bond programmatically using swift?

推荐答案

在您尝试向BLE设备的特征写入或从中读取时,都会启动配对.但是,如果未将设备设置为需要身份验证和/或绑定,则不会看到要求输入PIN码的iOS弹出窗口.

Pairing is initiated any time that you attempt to write to or read from a characteristic on the BLE device. However, if the device is not set to require authentication and/or bonding, you will not see the iOS popup which requests the PIN code.

我在HM-10上为此苦苦挣扎,因为我可以使用核心蓝牙(通过Swift)功能writeValue(),却没有看到配对弹出窗口.

I struggled with this with my HM-10 because I could write data to the characteristic using the Core Bluetooth (via Swift) function writeValue() without ever seeing the pairing popup.

直到仔细阅读HM-10(实现IC cc2451)数据表,然后发现需要将AT + TYPE设置为3时,我才能弄清楚.默认值为0,这意味着HM-10不需要配对/绑定,因此您永远不会看到iOS弹出窗口.

I couldn't figure it out until I read the HM-10 (implements the IC cc2451) datasheet very closely and found that I needed to set the AT+TYPE to value 3. It defaults to 0 which means that the HM-10 does not require pairing/bonding so you never see the iOS popup.

您可以在提出问题并最终找到解决方案并将其写下来的地方阅读更多详细信息:

You can read more about the details where I asked the question and ultimately found the solution and wrote it up: How do I pair and/or bond to BLE on iOS using Swift code and an HM-10 so data sent is encrypted?

这篇关于如何在Swift Xcode中以编程方式绑定/配对到蓝牙LE设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆