From 90080a34431b5175903958b2370cc5ac8dac86da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6hler?= Date: Thu, 6 Aug 2020 10:47:19 +0200 Subject: [PATCH 1/2] Update WBManager.swift --- WBCore/WBManager.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WBCore/WBManager.swift b/WBCore/WBManager.swift index 48ac616..06749c9 100644 --- a/WBCore/WBManager.swift +++ b/WBCore/WBManager.swift @@ -181,6 +181,26 @@ open class WBManager: NSObject, CBCentralManagerDelegate, WKScriptMessageHandler } device.triage(view) case .requestDevice: + if (centralManager.state != CBManagerState.poweredOn) { + transaction.resolveAsFailure(withMessage: "Bluetooth not activated.") + stopScanForPeripherals() + requestDeviceTransaction = nil + clearState() + + let alert = UIAlertController(title: NSLocalizedString("turn_on_bluetooth_title", comment: "Turn on bluetooth."), message: NSLocalizedString("turn_on_bluetooth_body", comment: "Please turn on bluetooth."), preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) + + let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first + if var topController = keyWindow?.rootViewController { + while let presentedViewController = topController.presentedViewController { + topController = presentedViewController + } + + topController.present(alert, animated: true) + } + + return + } guard transaction.key.typeComponents.count == 1 else { transaction.resolveAsFailure(withMessage: "Invalid request type \(transaction.key)") From 0e34eed1b6b40effb871bc6055a96f7757a99b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6hler?= Date: Thu, 6 Aug 2020 10:47:33 +0200 Subject: [PATCH 2/2] Update WBManager.swift --- WBCore/WBManager.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WBCore/WBManager.swift b/WBCore/WBManager.swift index 06749c9..c5526b6 100644 --- a/WBCore/WBManager.swift +++ b/WBCore/WBManager.swift @@ -190,6 +190,7 @@ open class WBManager: NSObject, CBCentralManagerDelegate, WKScriptMessageHandler let alert = UIAlertController(title: NSLocalizedString("turn_on_bluetooth_title", comment: "Turn on bluetooth."), message: NSLocalizedString("turn_on_bluetooth_body", comment: "Please turn on bluetooth."), preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) + // Find top most ViewController. let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first if var topController = keyWindow?.rootViewController { while let presentedViewController = topController.presentedViewController {