BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
Swift Ruby
Latest commit 9c36514 Jun 21, 2017 @1amageek committed on GitHub Merge pull request #2 from 1amageek/add-code-of-conduct-1
Create CODE_OF_CONDUCT.md
Permalink
Failed to load latest commit information.
Bleu.xcodeproj bugfix Mar 26, 2017
Sample Remake logo Jun 1, 2017
Sources Add comment Jun 1, 2017
.gitignore add .gitignore Mar 13, 2017
.swift-version bugfix Mar 19, 2017
Bleu.png Remake logo Jun 1, 2017
Bleu.podspec fix podspec Jun 1, 2017
Bleu.sketch Remake logo Jun 1, 2017
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Jun 22, 2017
LICENSE add license Mar 15, 2017
README.md Update README.md Jun 5, 2017

README.md

Bleu

Bleu is a Bluetooth library. Bleu is the easiest way to operate CoreBluetooth.

Bleu is possible to operate by replacing Bluetooth 's Peripheral and Central with Server and Client. Bleu can be developed event-driven.

Version Platform Awesome Downloads

Installation

CocoaPods

  • Insert pod 'Bleu' to your Podfile.
  • Run pod install.

Note: CocoaPods 1.1.0 is required to install Bleu.

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(isNotified: false)
    }
    
    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")
    }
}