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