Почему мое приложение iOS не перезапускается после восстановления состояния Bluetooth?IOS

Программируем под IOS
Anonymous
Почему мое приложение iOS не перезапускается после восстановления состояния Bluetooth?

Сообщение Anonymous »

Я пытаюсь заставить мое приложение iOS автоматически перезапускаться после завершения, когда мой CBCentralManager восстанавливает состояние. Я следовал рекомендациям Apple по восстановлению состояния Bluetooth, гарантируя, что мое приложение ожидает события Bluetooth (сканирование и подключение). Однако приложение не перезапускается после закрытия, хотя соединение BLE восстанавливается.

Код: Выделить всё

  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")
}
}
}
Затем я буду включать и выключать режим самолета (Bluetooth), чтобы не произойти приложение.

Подробнее здесь: https://stackoverflow.com/questions/793 ... estoration

Вернуться в «IOS»