iOSのBluetooth通信について質問があります。
このような形でBluetooth通信を作成しました。
この場合において、相手端末側との通信の切断が発生した場合の通知を受け取りたいのですが、どの様にすればよいのでしょうか。
よろしくお願い致します。
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
self.peripheral = peripheral
centralManager.connect(peripheral, options: nil)
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
centralManager.stopScan()
self.peripheral.delegate = self
self.peripheral.discoverServices([serviceUUID])
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if error != nil {
return
}
self.peripheral.discoverCharacteristics([charcteristicUUID], for: (peripheral.services?.first)!)
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if error != nil {
return
}
characteristic = service.characteristics?.first
isConnected = true;
}