【问题标题】:how to open contacts in ionic native [closed]如何在离子原生中打开联系人[关闭]
【发布时间】:2017-12-13 11:30:37
【问题描述】:

我的要求是使用离子原生打开原生联系。我用谷歌搜索但无法得到正确的答案

我们使用了这个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);
      })
   })

【问题讨论】:

  • 好吧,你应该添加你尝试过的东西。
  • @DiegoCardozo 我们能够获取所有联系人,但我们需要打开电话簿,我们没有像打开电话簿那样获得任何方法名称。请指导我们

标签: angular cordova ionic-framework contacts ionic-native


【解决方案1】:

但请记住,在 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)
                });
}

【讨论】:

  • 打开原生联系人界面后如何选择多个联系人?
  • 好吧,插件在这里帮不了你,你可以使用来自navigator.contacts.find(['*'], (contacts) => {})的数据创建一个自定义组件,然后你来处理选择。
猜你喜欢
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
相关资源
最近更新 更多