XCode 9.0 iOS 10 ++
add following file to your project.
Start the BLEManger
let queue = DispatchQueue.global()
centralManager = CBCentralManager(delegate: self, queue: queue)
Send Data
func sendData(data: Data, uuidString: String) throws {
guard let characteristic = charDictionary[uuidString] else {
throw SendDataError.CharacteristicNotFound
}
connectPeripheral.writeValue(
data,
for: characteristic,
type: .withResponse
)
}
Disconnect
centralManager.cancelPeripheralConnection(connectPeripheral)
Reconnect
centralManager.retrievePeripherals(withIdentifiers: [uuid])
Subscribe
if let characteristic = charDictionary[uuid.uuidString] {
connectPeripheral.setNotifyValue(true, for: characteristic)
}
Unsubscribe
if let characteristic = charDictionary[uuid.uuidString] {
connectPeripheral.setNotifyValue(false, for: characteristic)
}
ReadData
if let characteristic = charDictionary[uuid.uuidString] {
connectPeripheral.readValue(for: characteristic)
}
BookTw, [email protected]