Add the BLE.swift class to your project.
And let's assume you want to use the BLE object in a view controller:
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")
}
}
You can connect to a device using the following call:
bluetoothManager.connectToPeripheral(bluetoothManager.peripherals[index])
You can disconnect from a device using:
bluetoothManager.disconnectFromPeripheral(bluetoothManager.peripherals[index])
To send data use:
bluetoothManager.send(...some NSDATE...)