获取正确的联系人计数但在 Ionic 4 中获取联系人的空值

Getting count of contacts correct but getting null values for contacts in Ionic 4

我正在使用 ionic 联系人插件,它在 phone 中为我提供了正确的联系人数量,但所有详细信息字段均为空,

我正在使用, “cordova-plugin-contacts”: “3.0.1”, “@ionic-native/contacts”:“^5.0.0”

import { Contacts } from '@ionic-native/contacts/ngx';

constructor( private contactsPlugin: Contacts ) { }

document.addEventListener("deviceready", () => {

    this.contactsPlugin.find(["displayName", "phoneNumbers","photos"], {multiple: true, hasPhoneNumber: true})
      .then((contacts) => {
        console.log("Length: ", contacts.length);
        for(let i=0; i < contacts.length; i++){
          console.log('... ',contacts[i]);
          if ( contacts[i].displayName != null ) {
            console.log("--> ", contacts[i].displayName );
          }
        }
      }, 
      (error) => {
        console.error("Contacts error: ", error)
      })

});

这样解决的:

import { Contacts } from '@ionic-native/contacts/ngx';

declare var navigator: any;

@Component({
  selector: 'assignment',
  templateUrl: './assignment.page.html',
  styleUrls: ['./assignment.page.scss']
})

async getContacts() {
 await document.addEventListener("deviceready", () => {

  navigator.contacts.find(
    [navigator.contacts.fieldType.displayName],
    gotContacts,
    errorHandler);

    function errorHandler(e) {
      console.log("errorHandler: "+e);
    }

    function gotContacts(deviceContacts) {
    console.log("gotContacts, number of results " + deviceContacts.length);
      for(var i=0, len = deviceContacts.length; i<len; i++) {
            console.log("Contact >>>  ", deviceContacts[i]);
       }
    }
  }
}