我正在使用离子触点插件,它为我提供了电话中正确的联系人数量,但所有详细信息字段均为空,
我正在使用, “ cordova-plugin-contacts”:“ 3.0.1”, “ @ ionic-native / contacts”:“ ^ 5.0.0”
import { Contacts } from '@ionic-native/contacts/ngx';
constructor( private contactsPlugin: Contacts ) { }
document.addEventListener("deviceready", () => {
this.contactsPlugin.find(["displayName", "phoneNumbers","photos"], {multiple: true, hasPhoneNumber: true})
.then((contacts) => {
console.log("Length: ", contacts.length);
for(let i=0; i < contacts.length; i++){
console.log('... ',contacts[i]);
if ( contacts[i].displayName != null ) {
console.log("--> ", contacts[i].displayName );
}
}
},
(error) => {
console.error("Contacts error: ", error)
})
});
答案 0 :(得分:0)
像这样解决它:
import { Contacts } from '@ionic-native/contacts/ngx';
declare var navigator: any;
@Component({
selector: 'assignment',
templateUrl: './assignment.page.html',
styleUrls: ['./assignment.page.scss']
})
async getContacts() {
await document.addEventListener("deviceready", () => {
navigator.contacts.find(
[navigator.contacts.fieldType.displayName],
gotContacts,
errorHandler);
function errorHandler(e) {
console.log("errorHandler: "+e);
}
function gotContacts(deviceContacts) {
console.log("gotContacts, number of results " + deviceContacts.length);
for(var i=0, len = deviceContacts.length; i<len; i++) {
console.log("Contact >>> ", deviceContacts[i]);
}
}
}
}