1
嗨,这是我的第一个关于堆栈溢出的问题。Swift 2.0和BLE
我有一个来自RebLab的BLE Blend Micro,就像Arduino和BLE盾牌一样。
我发现这个:https://github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE
但我不知道我怎么能整合或调用函数,有人能帮助我吗?
嗨,这是我的第一个关于堆栈溢出的问题。Swift 2.0和BLE
我有一个来自RebLab的BLE Blend Micro,就像Arduino和BLE盾牌一样。
我发现这个:https://github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE
但我不知道我怎么能整合或调用函数,有人能帮助我吗?
将BLE.swift类添加到您的项目中。
而且让我们假设你想使用的BLE对象的视图控制器:
import UIKit
class ViewController: UIViewController, BLEDelegate {
var bluetoothManager : BLE!
override func viewDidLoad() {
super.viewDidLoad()
bluetoothManager = BLE()
bluetoothManager.delegate = self
bluetoothManager.startScanning(10)
}
func bleDidUpdateState() {
print("Called when ble update did state")
}
func bleDidConnectToPeripheral() {
print("Called when ble did connect to peripheral")
}
func bleDidDisconenctFromPeripheral() {
print("Called when ble did disconnect from peripheral")
}
func bleDidReceiveData(data: NSData?) {
//method called when you receive some data from the peripheral
print("Called when ble did receive data")
}
}
您可以使用下面的呼叫连接到设备:
bluetoothManager.connectToPeripheral(bluetoothManager.peripherals[index])
您可以从设备断开连接使用:
bluetoothManager.disconnectFromPeripheral(bluetoothManager.peripherals[index])
要发送的数据使用:
bluetoothManager.send(...some NSDATE...)
该组件仅仅是CoreBluetooth框架的包装。我建议先探索一下。 – Armin