我正在开发 Phonegap 应用程序并尝试获取设备的联系人。
我从this reference中所做的如下:
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// contacts Methods
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts[i].addresses.length; j++) {
alert("Pref: " + contacts[i].addresses[j].pref + "\n" +
"Type: " + contacts[i].addresses[j].type + "\n" +
"Formatted: " + contacts[i].addresses[j].formatted + "\n" +
"Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
"Locality: " + contacts[i].addresses[j].locality + "\n" +
"Region: " + contacts[i].addresses[j].region + "\n" +
"Postal Code: " + contacts[i].addresses[j].postalCode + "\n" +
"Country: " + contacts[i].addresses[j].country);
}
}
};
// onError: Failed to get the contacts
function onError(contactError){
alert('onError!');
}
在控制台中打印联系人时出现此错误-
[INFO] Error in success callback: Contacts1 = TypeError: 'null' is not an object
我的模拟器中有联系人,并且联系信息不为空,但我仍然为空。不确定原因。
请帮我。
编辑:当我播放音频文件时也会发生同样的事情..
任何人都知道为什么会这样?