Код: Выделить всё
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
// Stop scanning to save power after discovering the target peripheral
centralManager.stopScan()
self.discoveredPeripheral = peripheral
DispatchQueue.main.asyncAfter(deadline: .now() + 7) {
// Prepare connection options
let options: [String: Any] = [
CBConnectPeripheralOptionNotifyOnConnectionKey: true,
CBConnectPeripheralOptionNotifyOnDisconnectionKey: true,
CBConnectPeripheralOptionNotifyOnNotificationKey: true
]
// Connect to the peripheral
centralManager.connect(peripheral, options: options)
print("Simulating app crash before connecting to peripheral")
// 🔴 Trigger a crash to simulate unexpected app termination
fatalError("Simulating app crash for BLE restoration test")
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... estoration