2017-12-13 15 views
0

나의 요구 사항은 이온 네이티브를 사용하여 네이티브 연락처를 여는 것입니다. 검색 좀하지만 우리는이 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); 
     }) 
    }) 
+1

음, 시도한 것을 추가해야합니다. –

+0

@DiegoCardozo 우리는 모든 연락처를 얻을 수 있지만 열려있는 전화 번호부가 필요합니다. 우리는 전화 번호부와 같은 방법 이름을 얻지 못합니다. 우리에게 안내 해주십시오. –

답변

1

을하지만 이온에 당신은 당신이 처음 platform.ready() 대기해야 네이티브 API를 사용하려는 경우 기억 이 이벤트는 모든 것이로드되었고 사용할 준비가되었음을 알립니다.

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) 
       }); 
}