wheresmycookie
wheresmycookie

Reputation: 773

Notifying iOS user that bluetooth must be turned on

I have an app that uses long-term BLE scanning in the background. I would like to detect when Bluetooth has been turned off so that I can send the user a notification saying that the apps functionality will be limited. Is this possible?

Upvotes: 0

Views: 47

Answers (1)

Sandeep Bhandari
Sandeep Bhandari

Reputation: 20379

You can conform to CBCentralManagerDelegate and implement centralManagerDidUpdateState(_:) to be notified of the change in state

func centralManagerDidUpdateState(_ central: CBCentralManager) {
        switch central.state {
        case .poweredOn:
             debugPrint("Scanner powered on")
             break
        case .poweredOff:
            debugPrint("Scanner powered off")
            break
        case .resetting:
            debugPrint("Resetting scanner")
            break
        case .unauthorized:
            debugPrint("Unauthorized")
        case .unknown:
            debugPrint("unknown")
        case .unsupported:
            debugPrint("Scanner not supported")
        }
}

Hope this helps

Upvotes: 2

Related Questions