ionic获取手机通讯录contacts

打开控制台安装contacts插件

ionic cordova plugin add cordova-plugin-contacts
npm install @ionic-native/contacts

app.module.ts引入

import { Contacts } from '@ionic-native/contacts';`
providers: [ Contacts ] 

contact-list.ts引入

import { Contacts } from '@ionic-native/contacts';`
constructor(private contacts: Contacts) {  }

查找通讯录全部联系人:

this.contacts.find(['displayName', 'phoneNumbers'], {filter: "", multiple: true})
.then(contacts => {
  console.log(contacts);
  this.allContacts=contacts;
});

点击选择单个联系人:

this.contacts.pickContact().then((contact)=>{
  console.log("contacts:-->"+ JSON.stringify(contact));
  //this.familyDisplayName = contact.displayName; 
  //更新:这里有一个大坑,Android的全名显示在displayName,IOS的全名显示在name.formatted
  this.familyDisplayName = contact.displayName!=null?contact.displayName:contact.name.formatted; 
  this.familyPhoneNumbers = contact.phoneNumbers[0].value;  
});

你可能感兴趣的:(ionic获取手机通讯录contacts)