【问题标题】:Why am I able to load Contacts from my Android phone with the Cordova Contact API but not on ios?为什么我可以使用 Cordova 联系人 API 从我的 Android 手机加载联系人,但不能在 ios 上加载?
【发布时间】:2023-03-03 14:31:01
【问题描述】:

我正在使用构建在 Phonegap 之上的 dhtml 和 steroids.js 构建一个跨平台手机应用程序。我正在尝试使用 Cordova Contact API 将我手机中的联系人加载到 ul 元素中。这是我在头部标签中的代码。当我在我的 Android 设备上加载我的应用程序而不是在 iphone4 或 5 上时,它工作正常。

<script type="text/javascript" charset="utf-8">
 // 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);

var mycontact = contacts[i].displayName;
alert(mycontact);

//Just making sure if a contact is null, it won't be appended to the ul. 
if(mycontact == null){
}   
else
{
// Using a little jQuery to append to contacts to the ul
$("#contactlist").append('<li style="background-color:rgb (184,249,255);height:70px;overflow:hidden;border-top:solid 1px; border-bottom:solid 1px background-color:rgb(184,249,255);"><p style="font-family: Arial;font-size: 18px;top: 5px;position:   relative;left: 10px;">' + mycontact + '</p></li>');
  }

 }

 // ele.innerHTML = str;
 }

// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
</script>

【问题讨论】:

    标签: javascript cordova


    【解决方案1】:

    似乎使用filter = ["*"] 实际上并没有返回所有联系人字段。尝试明确声明要返回的字段,例如filter = ["displayName", "phoneNumbers"].

    这似乎是 Cordova 问题,但我无法快速找到任何支持我的假设的东西。

    【讨论】:

    • 是的,那没用 :( 实际上我现在正在尝试获取电话号码,但我无法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2015-03-24
    • 1970-01-01
    相关资源
    最近更新 更多