ble icon indicating copy to clipboard operation
ble copied to clipboard

(Android) enableGPS does not attempt to enable GPS due to incorrect isGPSEnabled check

Open delaneyb opened this issue 2 years ago • 1 comments

enableGPS uses the check

if (!this.isGPSEnabled())

to determine whether we need to prompt the user to enable location services on the device. isGPSEnabled however returns a Promise, meaning the non-awaited returned value is always truthy, and therefore enableGPS will never actually actually prompt the user to enable location services, even if the promise returned by isGPSEnabled resolves to false

https://github.com/nativescript-community/ble/blob/9820235506bea2bd27e82bc994cc512f6821b859/src/ble/index.android.ts#L1277-L1300

A simple solution would be to make the promise constructor callback async and adjust the condition to:

if (!(await this.isGPSEnabled()))

The check after receiving the request result from the system on line 1287 also needs to be corrected https://github.com/nativescript-community/ble/blob/9820235506bea2bd27e82bc994cc512f6821b859/src/ble/index.android.ts#L1287

delaneyb avatar Feb 11 '23 07:02 delaneyb

@delaneyb thanks for this. Tbh i dont use that part of the plugin. I always use the perms plugin and move the logic in the app. The reason is that the logic is constantly changing and getting more complex as new os versions are released I even think of removing that part and let the user handles it with the perms plugin. However if you want to make a PR to fix all this I would gladly merge it

farfromrefug avatar Feb 11 '23 08:02 farfromrefug