プロジェクトに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