xcode iPhone corebluetooth 中央管理器向外围设备发送数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19020782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:55:40  来源:igfitidea点击:

iPhone corebluetooth central Manager send data to peripheral

iosxcodeiphone-5xcode5core-bluetooth

提问by TechFanatic

I want to send data from iPhone to a bluetooth device which get discovered and connects. I am referring thistutorial to connect.

我想将数据从 iPhone 发送到被发现并连接的蓝牙设备。我指的是教程进行连接。

I am not able to send data to external bluetooth device which is connected as we do with External Accessory framework.

我无法像使用外部附件框架那样将数据发送到连接的外部蓝牙设备。

I am using iPhone5 as it has Bluetooth 4.0

我正在使用 iPhone5,因为它有蓝牙 4.0

回答by allprog

In Core Bluetooth you need to use the characteristics for communication. There is no standard stream based API like in the External Accessory Framework and I don't know of any open source libraries that implement something like that.

在 Core Bluetooth 中,您需要使用特性进行通信。没有像外部附件框架那样基于流的标准 API,我不知道有任何开源库实现了类似的东西。

Basic operation

基本操作

Peripheral -> Central:

外围 -> 中央:

  1. Central subscribes to characteristic (either with notifications or indications)
  2. Peripheral receives the subscribed callback so knows that the central is listening
  3. Peripheral updates characteristic
  4. Central receives characteristic updated notification
  1. Central 订阅特性(带有通知或指示)
  2. 外设收到订阅的回调,所以知道中心正在监听
  3. 外设更新特性
  4. 中央收到特征更新通知

Central -> Peripheral:

中央 -> 外围:

  1. Central writes characteristic
  2. Peripheral receives write request update
  1. 中写特性
  2. 外设接收写请求更新

The actual speed you can achieve depends on various factors. With indications the data is never lost (like TCP) but notifications don't have such guarantees (like UDP).

您可以达到的实际速度取决于各种因素。有了指示,数据永远不会丢失(如 TCP),但通知没有这样的保证(如 UDP)。

More info

更多信息

I suggest you check out the official Core Bluetooth Programming Guide and concentrate on the

我建议你查看官方的 Core Bluetooth Programming Guide 并专注于

sections. But better would be studying the whole guide as is. For a working example, check out the BTLE Transferexample from Apple, as well.

部分。但最好按原样研究整个指南。对于工作示例,也请查看Apple的BTLE Transfer示例。

回答by Gili Ariel

If i understand you correctly you want the central to send data to your peripheral.

如果我理解正确,您希望中​​央将数据发送到您的外围设备。

for that you use this method:

为此,您使用此方法:

[peripheral writeValue:dataPacket forCharacteristic:writeChar type:CBCharacteristicWithResponse]

回答by thatzprem

This is pretty compelling video to watch and know what exactly goes in iOS bluetooth framework. Its clearly explained what operations can be performed by central and peripheral systems.

这是一个非常引人注目的视频,可以观看并了解 iOS 蓝牙框架中的具体内容。它清楚地说明了中央和外围系统可以执行哪些操作。

https://developer.apple.com/videos/play/wwdc2012-705/

https://developer.apple.com/videos/play/wwdc2012-705/