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

时间:2015-10-24 02:34:05

标签: android ios cordova ionic

我的应用程序和一个测试设备(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");

2 个答案:

答案 0 :(得分: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"); 
                 }

答案 1 :(得分:0)

您可以使用navigator.contacts.find,看看它是否适用于您的手机。 更多细节 https://github.com/apache/cordova-plugin-contacts

相关问题