1

Hi this is my first question on stack overflow.

I have a BLE Blend Micro from RebLab, like Arduino with BLE shield.

I have find this: https://github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE

But I don't know how I can integrate or call the function, someone can help me?

Lasse Meyer
  • 1,429
  • 18
  • 38
  • That component is just a wrapper for the CoreBluetooth framework. I'd suggest exploring that first. – Armin Jul 27 '16 at 12:56

1 Answers1

0

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...)
vbgd
  • 1,937
  • 1
  • 13
  • 18