嗨,这是我关于堆栈溢出的第一个问题。
我有一个来自RebLab的BLE Blend Micro,就像带有BLE盾牌的Arduino。
我找到了这个:https://github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE
但我不知道如何整合或调用该功能,有人可以帮助我吗?
答案 0 :(得分:0)
将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...)