dpa99c / cordova-diagnostic-plugin

Cordova/Phonegap plugin to manage device settings
540 stars 361 forks source link

Requesting Location authoritation on iOS getting stuck #348

Closed UlisesCeca closed 5 years ago

UlisesCeca commented 5 years ago

Hello,

If I was already prompted to allow location on iOS and I deny it, then next time that I use the requestLocationAuthorization method, it gets stuck, doesn't go to success or error cb.

Is there a solution to this?

Thanks.

SpeckiJ commented 5 years ago

This is intended behaviour and caused by iOS limitations. As the Documentation of requestLocationAuthorization states:

This should only be called if authorization status is NOT_DETERMINED - calling it when in any other state will have no effect.

This limitation does not only apply to Cordova, but to all iOS Apps. see also here (Apple Developer Blog) or here (StackOverflow)

To circumvent this issue it would be easiest to handle the first time requesting the Location seperately from subsequent requests (e.g. check if your status is NOT_REQUESTED first, and then request permissions. If status is already set, you can display a hint to the user that he/she can change the permissions in the iOS Settings Menu).

dpa99c commented 5 years ago

@SpeckiJ thanks for this very clear description. Closing this since, as you rightly state, this is a limitation of iOS, not this plugin or Cordova.

UlisesCeca commented 5 years ago

It'd be good that the plugin sends you to the error callback at least instead of getting stuck forever. That doesnt look like a right behaviour to me.

dpa99c commented 5 years ago

In this case, the plugin calls the native location manager but the location manager doesn't raise an error and never invokes the callback delegate so the plugin can never know the request has not succeeded since there is no thread of execution by which it is invoked.

Adam4224 commented 4 years ago

Seems that a timeout parameter, which races a timeout against the request and then fails after the specified time would provide a better user experience than an unexpectedly hanging app. The situation I can think of where this might occur is if a plugin has requested the same permission and been denied.

Can fix as follows in calling code (typescript): var result : string = await Promise.race([Promise.wait(20000).then(t => "timed_out"), this.diagnostic.requestLocationAuthorization("when_in_use")]);