-
Notifications
You must be signed in to change notification settings - Fork 113
frontend: improve BT alert message #3700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
frontend: improve BT alert message #3700
Conversation
168ad88 to
726901c
Compare
f426d75 to
c5fb98a
Compare
benma
left a comment
There was a problem hiding this 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.
c5fb98a to
e79f75a
Compare
e79f75a to
13c1915
Compare
|
Rebased and addressed your comment. Sorry I forgot to ping last week. PTAL @benma 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if urlString == "app-settings:" { | ||
| if let url = URL(string: UIApplication.openSettingsURLString) { | ||
| // opens app settings page in the system settings | ||
| UIApplication.shared.open(url) | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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....
13c1915 to
2b635c2
Compare
Show different message when bluetooth is disabled system-wide vs app has no permission to use bluetooth.
2b635c2 to
4eb6f17
Compare

On iOS, Bluetooth can be “off” for two different reasons:
System Bluetooth is turned off
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:

If bluetooth permission is disabled specifically for BBApp:

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