简体   繁体   中英

How to unpair BLE device from our iOS app?

I am working with Linkey BLE lock to control from app. I am able to pair easily. But when I disconnect the peripheral I need to unpair from the peripheral. Can any one help me in this?

I'm a little confused since BLE works differently than classic Bluetooth and connects and disconnects to peripherals .

I'm assuming that you are connecting to the lock through the central manager and are needing to remove the reference to the peripheral. If so, in the object that handles the BLE connection just needs to clear all refereneces to the peripheral in the disconnect event listener:

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
// Something disconnected, check to see if it's our peripheral 
// If so, clear active device/service
if peripheral == self.blePeripheral {
  self.blePeripheral = nil
  self.bleService = nil
}

// Scan for new devices using the function you initially connected to the perhipheral
  self.scanForNewDevices()
}

Your peripheral should reconnect if it is on and in broadcast range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM