Search code examples
capacitor

Inconsistent Contacts.getPermissions() response with @capacitor-community/contacts plugin


In my Angular 13 Ionic 6 app, I am attempting to fetch all contacts for the user, in a component:

import { Contacts } from '@capacitor-community/contacts';

ngOnInit() {

    Contacts.getPermissions().then((response) => {
      console.log('Contacts permission response: ', response);
      if (response.granted) {
        console.log('Granted permissions for contacts');
        this.dialogs.openLoader('Your contacts are coming up...');
        Contacts.getContacts().then((result) => {
          this.foundContacts = true;
          console.log('Got contacts result: ', result);
          this.contacts = result.contacts;
          this.selectedContactName = '';
          this.dialogs.closeLoader();
        });
        
      }
    });

  }

The response coming back from the getPermissions() promise is inconsistent:

Upon initial run of the app, when the permissions dialog opens for the user, it returns this (console.log output):

Contacts permission response:  {contacts: 'granted'}

Re-openning the component without the permissions dialog box opening, it looks different:

Contacts permission response:  {granted: true}

In the first case, the IF test (response.granted) fails, which is not the expected behavior.

What is happening here?


Solution

  • It was a known issue reported on their issue tracker

    https://github.com/capacitor-community/contacts/issues/57

    Should be fixed on versions 3 and 4 of the plugin.