Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49085

Capacitor Permissions Not Showing Native Dialog

$
0
0

I’m creating an Ionic v5.x application using Angular v10.x with Capacitor v2.4.5, and I’m confused by Capacitor Permissions (specifically the Permissions plugin, and the associated requestPermission() methods for other plugins like Geolocation and LocalNotifications).

When the application opens it will request permissions which is expected, but when I test while the application is in use that they weren’t denied (or services were turned off) the use of requestPermissions for example const result = await LocalNotifications.requestPermissions(); always returns an empty object literal regardless of whether permissions were granted or denied. I know I can use const enabled = await LocalNotifications.areEnabled(); to check the permission state, but I thought that await LocalNotifications.requestPermissions() would show a native prompt. Is that not the case?

// Works as expected
public async hasNotificationPermissions()
  const permission = await Permissions.query({ name: PermissionType.Notifications });
  this.presentAlert('Permission Query', `${JSON.stringify(permission)}`); // Testing only
}

// Doesn't work as expected
public async requestPermissionsPlugin(): Promise<PermissionsRequestResult | null> {
  try {
    // Always an empty object literal ({})
    const result = await LocalNotifications.requestPermissions();

    // Expected to handle result or possibly directed into catch, but
    // instead always results an empty object literal everytime, which 
    // I tried with LocalNotifications, Geolocation, and Permissions

    this.presentAlert('Permissions Request', JSON.stringify(result)); // Testing only
    return result;
  } catch (e) {
    this.presentAlert('Permissions Request Exception', JSON.stringify(e)); // Testing only
  }

  return null;
}

I’ve tested this in emulation and on my Android device, and either way invoking requestPermissions doesn’t appear to do anything. How is requestPermissions() supposed to be used? I wish the documentation for Capacitor was a bit more verbose and had a few more examples.

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 49085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>