在iphone phonegap应用程序中显示联系人时获取空值

时间:2012-06-25 06:08:22

标签: iphone html ios5 cordova contacts

我正在处理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

我的模拟器中有联系人,联系信息不为空我仍然是空的。不确定原因。

请帮帮我。

编辑:当我播放音频文件时,同样的事情正在发生..

任何人都知道为什么会发生这种情况?

0 个答案:

没有答案