2016-07-26 3 views
1

こんにちは、これはスタックオーバーフローに関する私の最初の質問です。Swift 2.0とBLE

私はBLEシールド付きのArduinoのように、RebLabのBLE Blend Microを持っています。

私はこれを見つけるていますhttps://github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE

をしかし、私は誰かが私を助けることができる、機能を統合したり、呼び出すことができるのか分からないのですか?

+0

このコンポーネントは、CoreBluetoothフレームワークの単なるラッパーです。最初にそれを調べることをお勧めします。 – Armin

答えて

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...) 
関連する問題