-
-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Description
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
Lines 1277 to 1300 in 9820235
public enableGPS(): Promise<void> { | |
if (Trace.isEnabled()) { | |
CLog(CLogTypes.info, 'Bluetooth.enableGPS'); | |
} | |
return new Promise((resolve, reject) => { | |
const activity = andApp.foregroundActivity || andApp.startActivity; | |
if (!this.isGPSEnabled()) { | |
const onActivityResultHandler = (data: AndroidActivityResultEventData) => { | |
andApp.off(AndroidApplication.activityResultEvent, onActivityResultHandler); | |
if (data.requestCode === 0) { | |
if (this.isGPSEnabled()) { | |
resolve(); | |
} else { | |
reject('GPS not enabled'); | |
} | |
} | |
}; | |
andApp.on(AndroidApplication.activityResultEvent, onActivityResultHandler); | |
activity.startActivityForResult(new android.content.Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0); | |
} else { | |
resolve(); | |
} | |
}); | |
} |
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
Line 1287 in 9820235
if (this.isGPSEnabled()) { |
Metadata
Metadata
Assignees
Labels
No labels