0

I'm using Phonegap cli-8.0.0 to build my app.

When my app loads up for the first time it prompts the user with 2 permissions - location and notifications which is fine.

Now if a user accidentally taps the wrong button and denies the plugin is there away to check the permission has been denied? if so prompt a new request? rather than the user having to go in to phone settings > privacy etc...to allow permission

Plugins used:

  <plugin name="cordova-plugin-geolocation" spec="*" />
  <plugin name="phonegap-plugin-push" spec="2.1.3" />
Max Thorley
  • 173
  • 1
  • 17
  • Once the user has responded to the system prompt it won't be show again. The user must grant permissions in your app settings. Your app can check that permission is denied and display an alert asking the user to go to settings and grant the permissions. – Paulw11 Jul 23 '19 at 20:46

1 Answers1

1

You can use this plugin : https://github.com/dpa99c/cordova-diagnostic-plugin

It gives you the ability to check whether or not the user has refused the authorization and to ask again.

You can do it like this :

function requestLocationAuth(firstTime) {
    cordova.plugins.diagnostic.requestLocationAuthorization(function(status){
        var needRequest = false;
        switch(status){
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                needRequest = true;
                console.log("Permission not requested");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE: // Only Android
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                needRequest = true;
                console.log("Permission denied");
                break;
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted always");
                break;
            case cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE:
                console.log("Permission granted only when in use");
                break;
        }

        if (needRequest && firstTime) {
            requestLocationAuth(false);
        }

    }, function(error){
        console.error(error);
    }, cordova.plugins.diagnostic.locationAuthorizationMode.ALWAYS);
}

requestLocationAuth(true);
Enzo B.
  • 2,341
  • 1
  • 11
  • 33