一套高效且敏捷的IOS Ble溝通框架,幫助開發者快速部署你的藍牙應用.另外支持android版本
支持SwiftPackage。
class ViewController: UIViewController,BleCallBack {
var bles:[CBPeripheral]=[CBPeripheral]()
//連線中的回調
func onConnecting() {
print("onConnecting")
}
//連線失敗時回調
func onConnectFalse() {
print("onConnectFalse")
}
//連線成功時回調
func onConnectSuccess() {
print("onConnectSuccess")
}
//三種方式返回接收到的藍芽訊息
func rx(_ a: BleBinary) {
print("rx:\(a.readHEX())")
print("rx:\(a.readUTF())")
print("rx:\( a.readBytes())")
}
//三種方式返回傳送的藍芽訊息
func tx(_ b: BleBinary) {
print("tx:\(b.readHEX())")
print("tx:\(b.readUTF())")
print("tx:\( b.readBytes())")
}
//返回搜尋到的藍芽,可將搜尋到的藍芽儲存於陣列中,可用於之後的連線
func scanBack(_ device: CBPeripheral) {
if(!bles.contains(device)){
bles.append(device)
}
}
//藍芽未打開,經聽到此function可提醒使用者打開藍芽
func needOpen() {
print("noble")
}
}
lazy var helper=BleHelper(self)
helper.startScan()
helper.connect(bles[0], 10)
helper.stopScan()
helper.disconnect()
helper.writeHex("48656C6C6F20426C65", TxChannel, RxChannel)
helper.writeUtf("Hello Ble", TxChannel, RxChannel)
helper.writeBytes([0x48,0x65,0x6C,0x6C,0x6F,0x20,0x42,0x6C,0x65], TxChannel, RxChannel)
helper.writeData("Hello Ble".data(using: .utf8), TxChannel, RxChannel)
橙的電子android and ios developer
*line:sam38124
*gmail:sam38124@gmail.com