Swift Ruby
Latest commit f5cb68f Mar 19, 2017 @1amageek bugfix
Permalink
Failed to load latest commit information.
Bleu.xcodeproj bugfix Mar 19, 2017
Sample bugfix Mar 19, 2017
Sources bugfix Mar 19, 2017
.gitignore add .gitignore Mar 13, 2017
.swift-version
Bleu.png Add files via upload Mar 13, 2017
Bleu.podspec bugfix Mar 19, 2017
LICENSE add license Mar 15, 2017
README.md

README.md

Bleu

BLE for U🎁

Usage

Please customize Communicable+.swift.

uuidgen // create uuid
extension BLEService {
    
    public var serviceUUID: CBUUID {
        return CBUUID(string: "4E6C6189-D06B-4835-8F3B-F5CBC36560FB")
    }
    
}

struct GetUserIDItem: Communicable {
    
    public var method: RequestMethod {
        return .get
    }
    
    public var characteristicUUID: CBUUID {
        return CBUUID(string: "BC9E790A-5682-4B4E-9366-E81BB97107A1")
    }
    
}

struct PostUserIDItem: Communicable {
    
    public var method: RequestMethod {
        return .post
    }
    
    public var characteristicUUID: CBUUID {
        return CBUUID(string: "55B59CD5-8B59-4BA8-9050-AA4B2320294F")
    }
    
}

πŸ˜ƒ Get

Peripheral(Server)

Bleu.addRecevier(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(item: GetUserID())
Bleu.send(request) { (peripheral, characteristic, error) in
    
    if let error = error {
        debugPrint(error)
        return
    }
    
    let data: Data = characteristic.value!
    let text: String = String(data: data, encoding: .utf8)!
    print(text)
}

πŸ˜ƒ Post

Peripheral(Server)

Bleu.addRecevier(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(item: PostUserID())
request.value = data
Bleu.send(request) { (peripheral, characteristic, error) in
    
    if let error = error {
        debugPrint(error)
        return
    }
    
    print("success")
}