Bleu 0.3.3

Bleu 0.3.3

TestsTested ✗
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2017
SwiftSwift Version 3.1
SPMSupports SPM ✗

Maintained by 1amageek.


Downloads

Total36
Week6
Month14

Installs

Apps12
Apps WeekApps This Week 6
powered by Segment

GitHub

Stars408
Watchers9
Forks23
Issues0
Contributors2
Pull Requests0

Code

Files6
LOCLines of Code 771


Bleu 0.3.3

Bleu is a library that can handle CoreBluetooth easily.

Usage

Please customize Communicable+.swift.

uuidgen // create uuid
extension Communicable {

    public var serviceUUID: CBUUID {
        return CBUUID(string: "YOUR UUID")
    }

}

struct GetUserIDItem: Communicable {

    public var method: RequestMethod {
        return .get
    }

    public var characteristicUUID: CBUUID {
        return CBUUID(string: "YOUR UUID")
    }

}

struct PostUserIDItem: Communicable {

    public var method: RequestMethod {
        return .post
    }

    public var characteristicUUID: CBUUID {
        return CBUUID(string: "YOUR UUID")
    }

}

😃 Get

Peripheral(Server)

Bleu.addReceiver(Receiver(GetUserID(), get: { [weak self] (manager, request) in
    guard let text: String = self?.textField.text else {
        manager.respond(to: request, withResult: .attributeNotFound)
        return
    }
    request.value = text.data(using: .utf8)
    manager.respond(to: request, withResult: .success)
}))

Bleu.startAdvertising()

Central(Client)

let request: Request = Request(communication: GetUserID()) { [weak self] (peripheral, characteristic, error) in
    if let error = error {
        debugPrint(error)
        return
    }

    let data: Data = characteristic.value!
    let text: String = String(data: data, encoding: .utf8)!

    self?.centralTextField.text = text
}
Bleu.send([request]) { completedRequests, error in
    if let error = error {
        print("timeout")
    }
}

😃 Post

Peripheral(Server)

Bleu.addReceiver(Receiver(PostUserID(), post: { (manager, request) in
    let data: Data = request.value!
    let text: String = String(data: data, encoding: .utf8)!
    print(text)
    manager.respond(to: request, withResult: .success)
}))

Bleu.startAdvertising()

Central(Client)

let data: Data = "Sample".data(using: .utf8)!
let request: Request = Request(communication: PostUserID()) { (peripheral, characteristic, error) in
    if let error = error {
        debugPrint(error)
        return
    }

    print("success")
}
request.value = data
Bleu.send([request]) { completedRequests, error in
    if let error = error {
        print("timeout")
    }
}