Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions WBCore/WBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,27 @@ 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))

// Find top most ViewController.
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)")
Expand Down