我正在使用Phonegap构建电话应用程序。我正在尝试使用Cordova联系人API来检索手机上的联系人姓名。这是我当前的代码。它适用于Android设备。它只是从电话中获取联系人并将其附加到ul元素。我使用一个小jQuery的追加。Cordova Contact API中的displayName属性允许您获取电话上的联系人名称。我只是意识到ios不支持它。我试过contacts [I] .name; 在我的代码中也一无所获。如果有人可以告诉我ios支持什么属性,我将不胜感激。如何在iphone4或5上获取联系人的姓名?
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// find all contacts
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var filter = ["*"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
//alert(contacts[i].displayName);
//make if statement where
var mycontact = contacts[i].displayName;
///alert(mycontact);
if(mycontact == null){
}
else …Run Code Online (Sandbox Code Playgroud)