ionic获取手机通讯录

打开控制台安装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; 
  this.familyPhoneNumbers = contact.phoneNumbers[0].value;  
});
上一篇:Cloning into ‘ali-coion-fg‘... The authenticity of host ‘code.aliyun.com (xxxx)‘ can‘t be


下一篇:PAT 甲级 1139 First Contact (30 分)