Skip to content

Conversation

@shonsirsha
Copy link
Collaborator

@shonsirsha shonsirsha commented Dec 1, 2025

On iOS, Bluetooth can be “off” for two different reasons:

  1. System Bluetooth is turned off

  2. Bluetooth permission is disabled specifically for BitBoxApp

This commit adds logic to distinguish between these cases and
shows the appropriate message for each.

If system bluetooth is turned off:
Screenshot 2025-12-02 at 06 29 28

If bluetooth permission is disabled specifically for BBApp:
Screenshot 2025-12-01 at 14 01 52

On clicking "Enable", user will be brought to the Application settings:
IMG_6736

@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch 3 times, most recently from 168ad88 to 726901c Compare December 1, 2025 13:46
@shonsirsha shonsirsha requested a review from benma December 2, 2025 05:11
@shonsirsha shonsirsha marked this pull request as ready for review December 2, 2025 05:12
@shonsirsha shonsirsha changed the title WIP frontend: improve BT alert message WIP frontend: improve BT alert message WIP Dec 2, 2025
@shonsirsha shonsirsha changed the title frontend: improve BT alert message WIP frontend: improve BT alert message Dec 2, 2025
@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch 3 times, most recently from f426d75 to c5fb98a Compare December 2, 2025 05:33
Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, but I still need to test.

@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch from c5fb98a to e79f75a Compare December 8, 2025 11:41
@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch from e79f75a to 13c1915 Compare December 17, 2025 05:29
@shonsirsha
Copy link
Collaborator Author

Rebased and addressed your comment. Sorry I forgot to ping last week. PTAL @benma 🙏

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_2025-12-18_09-05-08

Something went wrong with the commit, the title/author/type are not the right one. Also in this commit you mixed Bluetooth stuff with other stuff somehow 😅

Comment on lines +122 to +140
if urlString == "app-settings:" {
if let url = URL(string: UIApplication.openSettingsURLString) {
// opens app settings page in the system settings
UIApplication.shared.open(url)
}
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this not just added as another if case above to set the url var? Why move all of it into the async callback have a separate section about app-settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The assignment of url below this doesnt need to be on the main thread.

But I think UIApplication.shared.open has to be executed on the main thread.

Use UIKit classes only from your app’s main thread or main dispatch queue, unless otherwise indicated in the documentation for those classes... [1]

And UIApplication is a part of UIKit [2]

Sources:

[1] https://developer.apple.com/documentation/uikit
[2] https://developer.apple.com/documentation/uikit/uiapplication/

print("BLE: on")
restartScan()
}
case .poweredOff, .unauthorized, .unsupported, .resetting, .unknown:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in the current, code, if unauthorized but Bluetooth is off, the message will be to allow Bluetooth. Shouldn't it prioritize saying to turn on Bluetooth in that case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I think that makes sense too. But I see that this may be a limitation in CoreBluetooth. When the app has no permission for BT, it simply reports unauthorized - it doesn't know whether BT is currently poweredOn or poweredOff. Only when the app has permission to use BT, it can tell the on/off state of the BT.

// user denied BT permission,
// or restricted by device policy
let authorization = CBManager.authorization
state.bluetoothUnauthorized = (authorization == .denied || authorization == .restricted)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as state.bluetoothUnauthorized = central.state == .unauthorized? If not, why not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'm still re-learning Swift, and it seems like that they aren't the same.

AFAIK central.state is the system-level and not app-level (app level BT-permission is only available in iOS 13+ btw).

So if BT is turned off app-level, but the BT is on in the settings, the central.state will be poweredOn and not unauthorized.

CBManager.authorization is what we rely on to check for the app-level BT permission.

Copy link
Collaborator Author

@shonsirsha shonsirsha Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benma sorry. I think my comment above is incorrect. I just tested state.bluetoothUnauthorized = central.state == .unauthorized and it yields the same result as using CBManager....

@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch from 13c1915 to 2b635c2 Compare December 22, 2025 12:49
Show different message when bluetooth is disabled system-wide
vs app has no permission to use bluetooth.
@shonsirsha shonsirsha force-pushed the frontend-improve-alert-message branch from 2b635c2 to 4eb6f17 Compare December 22, 2025 12:51
@shonsirsha
Copy link
Collaborator Author

Thanks a lot for your review @benma .

  1. Fixed the commit
  2. Addressed/answered comments
  3. Q: Which message is rendered when both the app-level BT permission is denied and system-wide BT is turned off?
    A: Read here

PTAL 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants