2016-07-26 77 views

回答

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...)