Cordova 联系人插件并不总是显示联系人列表

3

我在我的应用程序中使用了联系人插件,在一个测试设备上(iPhone 5,iOS 9.02),联系人列表不显示。当我进行搜索时,什么也没有出现。我没有收到任何错误消息。在一些其他设备上,如一些Android或iOS 8.x设备上,它是可以工作的。这个特定的问题设备有1200个联系人。有人有解决方法吗?我会粘贴代码的相关部分,虽然也许更多的是配置问题?

$scope.getAllContacts = function(searchQuery) {
    try {
        var opts = { //search options
            filter: searchQuery, // 'Bob'
            multiple: true, // Yes, return any contact that matches criteria
            fields: ['displayName', 'name']
        };
        if (ionic.Platform.isAndroid()) {
            opts.hasPhoneNumber = true; //hasPhoneNumber only works for android.
        };

        $ionicLoading.show();

        $cordovaContacts.find(opts).then(function(contactsFound) {
            $scope.contacts = contactsFound;
            $ionicLoading.hide();
        });


    } catch (err) {
        alert(err.message);
    }
};

$scope.getAllContacts("Ak");

1
尝试在“contactsFound”上注释代码,只需放置一个警报,看看是否通过。如果是,则表示某些东西需要太长时间来处理。我曾经遇到过类似的情况,但是在Phonegap上,我将进程分配到多个进程中以获得结果。顺便说一句,我有5000个联系人。 - Murtaza Khursheed Hussain
如果插件未按预期工作,请在 issues.cordova.io 上提交问题。 - jcesarmobile
2个回答

0

嗨,使用这个代码将所有联系人保存在SD卡中并显示出来。(默认使用Cordova联系人和文件插件)

     document.addEventListener("deviceReady", deviceReady, false);

  function deviceReady() {

navigator.contacts.find(["*"], function(contacts) {

  //  alert("contacts.length = " + contacts.length);

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getFile("contacts.json", {create: true, exclusive: false}, function(fileEntry) {
            fileEntry.createWriter(function(writer) {
                writer.onwriteend = function(){
                  // Success Contacts saved to sdcard as a contacts.json file
                  // Now get and read the json file 

    var path = fileSystem.root.getFile("contacts.json", {create:false},gotFileEntry, fail);

   // jquery

   $.getJSON(path, function (data) {

    user = data;
    $.each(user, function (index, user) {
        var all_item = '<p id="'+user.id+'">'+user.displayName+'</p>';
        $('#allcontacts').append(all_item);
    });
});
                };
                writer.write(JSON.stringify(contacts));

            }, onError);

        }, onError);

    }, onError);

}, onError,{"multiple": true});}  
        function onError(){
            alert("Error"); 
                 }

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接