Closed andreacab2 closed 2 years ago
We are experiencing exactly this issue.
On iOS there is no explicit method in the iOS Bluetooth manager to request permission.
Instead, any interaction with the native Bluetooth Manager class - even initialising it - causes the Bluetooth permission dialog to be shown to the user.
Hence if you call getBluetoothState()
or registerBluetoothStateChangeHandler()
after a fresh app install, the permission dialog will be shown because the plugin has to init the Bluetooth Manager in order to check the Bluetooth state.
Once the user has denied Bluetooth permission - either by pressing "Don't Allow" in the permission dialog or switching off Bluetooth permission on the app's Settings page - it is not possible to programmatically request it again (i.e. show the dialog). At this point, the app must show a message to the user requesting them to manually re-enable Bluetooth.
So the current implementation is misleading as it indicates that it can programmatically recover from Bluetooth being unauthorized - it cannot.
I'll push a commit which handles this situation more gracefully.
Fix released in cordova.plugins.diagnostic@7.1.1
Hey thanks for the explanation, it makes sense and thanks for the improvements as well, appreciated!
Bug report
CHECKLIST
Current behavior:
When you click on "Request Bluetooth Authorization" when the bluetooth state shows "UNAUTHORIZED", you are not asked to authorize anymore and in the native logs, it fails with a native error API MISUSE telling that the CBCentralManager needs to be in powered_on state (look for MISUSE in the native logs trail pasted below).
I have used the example code of the cordova-diagnostic-plugin and was able to reliably reproduce the issue.
Expected behavior:
To my understanding, using
diagnostic.requestBluetoothAuthorization
should ask again for authorization specifically in the case where the bluetooth state isUNAUTHORIZED
to change it toAUTHORIZED
Steps to reproduce:
UNAUTHORIZED
, Bluetooth authorization status should beDENIED_ALWAYS
Screenshots
Environment information
Runtime issue
iOS build issue:
Related code:
Console output
console output
``` 2022-08-26 11:09:22.043061+0200 Diagnostic plugin example[11240:3532018] Apache Cordova native platform version 6.2.0 is starting. 2022-08-26 11:09:22.043144+0200 Diagnostic plugin example[11240:3532018] Multi-tasking -> Device: YES, App: YES 2022-08-26 11:09:22.048447+0200 Diagnostic plugin example[11240:3532018] Could not load the "LaunchStoryboard" image referenced from a nib in the bundle with identifier "cordova.plugins.diagnostic.example" 2022-08-26 11:09:22.158084+0200 Diagnostic plugin example[11240:3532018] The preference key "AllowNewWindows" is not defined and will default to "FALSE" 2022-08-26 11:09:22.196959+0200 Diagnostic plugin example[11240:3532018] The preference key "MediaPlaybackAllowsAirPlay" is not defined and will default to "TRUE" 2022-08-26 11:09:22.199934+0200 Diagnostic plugin example[11240:3532018] The preference key "AllowBackForwardNavigationGestures" is not defined and will default to "FALSE" 2022-08-26 11:09:22.200000+0200 Diagnostic plugin example[11240:3532018] The preference key "Allow3DTouchLinkPreview" is not defined and will default to "TRUE" 2022-08-26 11:09:22.200030+0200 Diagnostic plugin example[11240:3532018] CDVWebViewEngine will reload WKWebView if required on resume 2022-08-26 11:09:22.200055+0200 Diagnostic plugin example[11240:3532018] Using WKWebView 2022-08-26 11:09:22.200600+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][console] 0.133038ms 2022-08-26 11:09:22.200877+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][handleopenurl] 0.095963ms 2022-08-26 11:09:22.202201+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][intentandnavigationfilter] 1.253963ms 2022-08-26 11:09:22.202313+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][gesturehandler] 0.038981ms 2022-08-26 11:09:22.202610+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic] 0.263095ms 2022-08-26 11:09:22.203813+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_location] 1.152992ms 2022-08-26 11:09:22.203881+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_bluetooth] 0.028968ms 2022-08-26 11:09:22.204058+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_wifi] 0.117898ms 2022-08-26 11:09:22.204129+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_camera] 0.024915ms 2022-08-26 11:09:22.204198+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_notifications] 0.041008ms 2022-08-26 11:09:22.204422+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_microphone] 0.097990ms 2022-08-26 11:09:22.205893+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_contacts] 1.384974ms 2022-08-26 11:09:22.205977+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_calendar] 0.034094ms 2022-08-26 11:09:22.206016+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_reminders] 0.010967ms 2022-08-26 11:09:22.206270+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][diagnostic_motion] 0.223994ms 2022-08-26 11:09:22.207227+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][file] 0.898004ms 2022-08-26 11:09:22.208484+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][statusbar] 1.208901ms 2022-08-26 11:09:22.208541+0200 Diagnostic plugin example[11240:3532018] [CDVTimer][TotalPluginStartup] 8.208036ms 2022-08-26 11:09:22.356453+0200 Diagnostic plugin example[11240:3532018] The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE" 2022-08-26 11:09:22.380249+0200 Diagnostic plugin example[11240:3532018] Diagnostic[native]: Debug enabled 2022-08-26 11:09:33.306770+0200 Diagnostic plugin example[11240:3532336] Diagnostic[native]: Location authorization status is: not_determined 2022-08-26 11:09:33.307024+0200 Diagnostic plugin example[11240:3532337] Diagnostic[native]: Location accuracy authorization is: reduced 2022-08-26 11:09:33.351905+0200 Diagnostic plugin example[11240:3532334] Diagnostic[native]: Battery level: 100 2022-08-26 11:09:33.352390+0200 Diagnostic plugin example[11240:3532018] THREAD WARNING: ['Diagnostic'] took '44.623291' ms. Plugin should use a background thread. 2022-08-26 11:09:33.352644+0200 Diagnostic plugin example[11240:3532334] Diagnostic[native]: Wifi ON 2022-08-26 11:09:33.353725+0200 Diagnostic plugin example[11240:3532337] Diagnostic[native]: Camera available 2022-08-26 11:09:33.354861+0200 Diagnostic plugin example[11240:3532336] Diagnostic[native]: Camera available 2022-08-26 11:09:33.359136+0200 Diagnostic plugin example[11240:3532351] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:33.359378+0200 Diagnostic plugin example[11240:3532351] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:33.359688+0200 Diagnostic plugin example[11240:3532351] Diagnostic[native]: Current CPU architecture: ARMv8 2022-08-26 11:09:33.365047+0200 Diagnostic plugin example[11240:3532217] Diagnostic[native]: Calendar event authorization status 2022-08-26 11:09:33.365267+0200 Diagnostic plugin example[11240:3532339] Diagnostic[native]: Camera authorization status is: not_determined is: not_determined 2022-08-26 11:09:33.366396+0200 Diagnostic plugin example[11240:3532349] Diagnostic[native]: Reminders authorization status is: not_determined 2022-08-26 11:09:33.366633+0200 Diagnostic plugin example[11240:3532342] Diagnostic[native]: Microphone authorization status is: not_determined 2022-08-26 11:09:33.367277+0200 Diagnostic plugin example[11240:3532346] Diagnostic[native]: Address book authorization status is: not_determined 2022-08-26 11:09:33.368984+0200 Diagnostic plugin example[11240:3532343] Diagnostic[native]: Remote notifications authorization status is: not_determined 2022-08-26 11:09:33.371746+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Camera Roll authorization status is: not_determined 2022-08-26 11:09:49.554785+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Bluetooth state changed: State unknown, update imminent. 2022-08-26 11:09:49.559910+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Location authorization status is: not_determined 2022-08-26 11:09:49.560234+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Location accuracy authorization is: reduced 2022-08-26 11:09:49.560666+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Camera authorization status is: not_determined 2022-08-26 11:09:49.561517+0200 Diagnostic plugin example[11240:3532339] Diagnostic[native]: Camera available 2022-08-26 11:09:49.561817+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Battery level: 100 2022-08-26 11:09:49.561872+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Camera available 2022-08-26 11:09:49.563891+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Camera Roll authorization status is: not_determined 2022-08-26 11:09:49.563871+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Wifi ON 2022-08-26 11:09:49.564337+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Bluetooth state changed: State unknown, update imminent. 2022-08-26 11:09:49.564632+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Bluetooth state changed: State unknown, update imminent. 2022-08-26 11:09:49.565048+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Microphone authorization status is: not_determined 2022-08-26 11:09:49.566257+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Bluetooth state is: unknown 2022-08-26 11:09:49.566347+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Address book authorization status is: not_determined 2022-08-26 11:09:49.568107+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Reminders authorization status is: not_determined 2022-08-26 11:09:49.568150+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Calendar event authorization status is: not_determined 2022-08-26 11:09:49.568271+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.568273+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.569187+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Current CPU architecture: ARMv8 2022-08-26 11:09:49.573232+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Remote notifications authorization status is: not_determined 2022-08-26 11:09:49.573433+0200 Diagnostic plugin example[11240:3532339] Diagnostic[native]: Location authorization status is: not_determined 2022-08-26 11:09:49.573625+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Location accuracy authorization is: reduced 2022-08-26 11:09:49.574669+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Camera authorization status is: not_determined 2022-08-26 11:09:49.575049+0200 Diagnostic plugin example[11240:3532339] Diagnostic[native]: Camera available 2022-08-26 11:09:49.575293+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Wifi ON 2022-08-26 11:09:49.575364+0200 Diagnostic plugin example[11240:3532453] Diagnostic[native]: Bluetooth state changed: State unknown, update imminent. 2022-08-26 11:09:49.575508+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Bluetooth state changed: State unknown, update imminent. 2022-08-26 11:09:49.575908+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Camera available 2022-08-26 11:09:49.575966+0200 Diagnostic plugin example[11240:3532335] Diagnostic[native]: Battery level: 100 2022-08-26 11:09:49.576198+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Microphone authorization status is: not_determined 2022-08-26 11:09:49.576522+0200 Diagnostic plugin example[11240:3532456] Diagnostic[native]: Calendar event authorization status is: not_determined 2022-08-26 11:09:49.576519+0200 Diagnostic plugin example[11240:3532455] Diagnostic[native]: Address book authorization status is: not_determined 2022-08-26 11:09:49.576667+0200 Diagnostic plugin example[11240:3532457] Diagnostic[native]: Reminders authorization status is: not_determined 2022-08-26 11:09:49.576662+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.576751+0200 Diagnostic plugin example[11240:3532458] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.577086+0200 Diagnostic plugin example[11240:3532463] Diagnostic[native]: Current CPU architecture: ARMv8 2022-08-26 11:09:49.579224+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Bluetooth state is: unknown 2022-08-26 11:09:49.582860+0200 Diagnostic plugin example[11240:3532458] Diagnostic[native]: Remote notifications authorization status is: not_determined 2022-08-26 11:09:49.584290+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Camera Roll authorization status is: not_determined 2022-08-26 11:09:49.590680+0200 Diagnostic plugin example[11240:3532018] Diagnostic[native]: Bluetooth state changed: The app is not authorized to use Bluetooth Low Energy. 2022-08-26 11:09:49.597675+0200 Diagnostic plugin example[11240:3532458] Diagnostic[native]: Location authorization status is: not_determined 2022-08-26 11:09:49.597839+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Location accuracy authorization is: reduced 2022-08-26 11:09:49.598067+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Camera authorization status is: not_determined 2022-08-26 11:09:49.598248+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Wifi ON 2022-08-26 11:09:49.598429+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Bluetooth state changed: The app is not authorized to use Bluetooth Low Energy. 2022-08-26 11:09:49.598500+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Bluetooth state changed: The app is not authorized to use Bluetooth Low Energy. 2022-08-26 11:09:49.598547+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Bluetooth state is: unauthorized 2022-08-26 11:09:49.598649+0200 Diagnostic plugin example[11240:3532454] Diagnostic[native]: Microphone authorization status is: not_determined 2022-08-26 11:09:49.598837+0200 Diagnostic plugin example[11240:3532457] Diagnostic[native]: Camera available 2022-08-26 11:09:49.598915+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Battery level: 100 2022-08-26 11:09:49.599099+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Calendar event authorization status is: not_determined 2022-08-26 11:09:49.599217+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.599239+0200 Diagnostic plugin example[11240:3532458] Diagnostic[native]: Camera available 2022-08-26 11:09:49.599230+0200 Diagnostic plugin example[11240:3532457] Diagnostic[native]: Background updates are available for the app. 2022-08-26 11:09:49.599389+0200 Diagnostic plugin example[11240:3532456] Diagnostic[native]: Reminders authorization status is: not_determined 2022-08-26 11:09:49.599434+0200 Diagnostic plugin example[11240:3532447] Diagnostic[native]: Address book authorization status is: not_determined 2022-08-26 11:09:49.599504+0200 Diagnostic plugin example[11240:3532445] Diagnostic[native]: Current CPU architecture: ARMv8 2022-08-26 11:09:49.600400+0200 Diagnostic plugin example[11240:3532353] Diagnostic[native]: Camera Roll authorization status is: not_determined 2022-08-26 11:09:49.602320+0200 Diagnostic plugin example[11240:3532449] Diagnostic[native]: Remote notifications authorization status is: not_determined 2022-08-26 11:10:05.947503+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Bluetooth state changed: The app is not authorized to use Bluetooth Low Energy. 2022-08-26 11:10:05.947774+0200 Diagnostic plugin example[11240:3532446] Diagnostic[native]: Requesting bluetooth authorization 2022-08-26 11:10:05.948017+0200 Diagnostic plugin example[11240:3532446] [CoreBluetooth] API MISUSE:**Other information:**