如何在 ionic native 中打开联系人

how to open contacts in ionic native

我的要求是使用ionic native打开native contact。我用谷歌搜索但无法得到正确答案

我们用了这个ionic Native contacts plugin

获取所有联系人:

this.platform.ready().then(() => {
      var opts = {   
         filter : "M",                                
         multiple: true,        
         hasPhoneNumber:true,                             
         fields:  [ 'displayName', 'name' ]
       };
       contacts.find([ 'displayName', 'name' ],opts).then((contacts) => {
         console.log(contacts);
        this.contactlist=contacts;
      }, (error) => {
        console.log(error);
      })
   })

但请记住,如果您想在 Ionic 中使用 Native API,您必须先等待 platform.ready() 此事件将通知所有内容已加载并可以使用。

import { Platform } from 'ionic-angular';
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';

constructor(private contacts: Contacts, private plt: Platform) {   
   this.plt.ready().then((readySource) => {
      console.log('Platform ready from', readySource);
      // Platform now ready, execute any required native code
      this.initContacts();
    });
}

initContacts(): void {
   let contact: Contact = this.contacts.create();

   contact.name = new ContactName(null, 'Smith', 'John');
   contact.phoneNumbers = [new ContactField('mobile', '6471234567')];
   contact.save().then(
     () => console.log('Contact saved!', contact),
     (error: any) => console.error('Error saving contact.', error)
   );

   // If you want to open the native contacts screen and select the contacts from there use pickContact()

   this.contacts.pickContact()
                .then((response: Contact) => { 
                   console.log(response)
                });
}