Angular 如何在ionic native中打开联系人
我的要求是使用ionic native打开本机触点。我在谷歌上搜索了一下,但找不到正确的答案 我们用这个 获取所有联系人:Angular 如何在ionic native中打开联系人,angular,cordova,ionic-framework,contacts,ionic-native,Angular,Cordova,Ionic Framework,Contacts,Ionic Native,我的要求是使用ionic native打开本机触点。我在谷歌上搜索了一下,但找不到正确的答案 我们用这个 获取所有联系人: this.platform.ready().then(() => { var opts = { filter : "M", multiple: true, hasPhoneNumber:true,
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中,如果您想使用本机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)
});
}
但请记住,在Ionic中,如果您想使用本机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)
});
}
好的,您应该添加您尝试过的内容。@DiegoCardozo我们可以获取所有联系人,但我们需要打开电话簿,我们无法获取任何类似打开电话簿的方法名称。请指导我们好的,您应该添加您尝试过的内容。@DiegoCardozo我们可以获得所有联系人,但我们需要打开电话簿,我们无法获得任何类似打开电话簿的方法名称。请指导我们如何在打开本机联系人屏幕后选择多个联系人?嗯,该插件在这里对您没有帮助,您可以使用
navigator.contacts.find(['*'],(contacts)=>{}中的数据创建自定义组件
您将处理选择。打开本机联系人屏幕后,我应该如何选择多个联系人?嗯,该插件在这里对您没有帮助,您可以使用navigator.contacts.find(['*'],(contacts)=>{})中的数据创建一个自定义组件,然后您将处理选择。