I have a development of an app using the Ionic4 Framework in which I must import the native contacts book of the device using the plugin @ionic-native/contacts . What happens is that the values corresponding to the displayName and phoneNumbers parameters are not properly returned; in fact, they return null values. For demonstration purposes I put an alert() that receives the parameters to show my problem:
I also share the code fragment where I make the call of the plugin and use it:
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts/ngx';
...
export class ImportarContactosPage {
listaContactos: any;
constructor(public contacts: Contacts) {
this.listarContactos();
}
...
listarContactos(){
this.contacts.find(["*"])
.then(res => {
// Alert
alert(JSON.stringify(res));
//
let datosMostar:any[]=[];
res.map((item) =>{
if(item.displayName != null && item.photos != null && item.phoneNumbers != null){
datosMostar.push({displayName:item.displayName,photos:[{value:this.avatar}],phoneNumbers:item.phoneNumbers})
}
})
console.log(datosMostar);
this.listaContactos = datosMostar;
},error => {
console.log({error:error});
})
}
...
}
my ionic-info :
Ionic CLI : 5.0.0 (C:\Users\Carlos\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0
@angular-devkit/build-angular : 0.11.4
@angular-devkit/schematics : 7.1.2
@angular/cli : 7.1.0
@ionic/angular-toolkit : 1.2.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.0.0
Utility:
cordova-res : 0.3.0
native-run : 0.2.5
System:
Android SDK Tools : 26.1.1 (C:\Users\Carlos\AppData\Local\Android\Sdk)
NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.9.0
OS : Windows 7
I have been “googling” and reviewing forums for several days and I have tried in many ways to import contacts, but I have not been able to correct the problem.
Any fellow idea, have I done something wrong? Any suggestion is welcome. Thank you.
