2015-10-24 103 views
3

我的應用程序和一個測試設備(iPhone 5,iOS 9.02)的聯繫人插件沒有顯示聯繫人列表。當我搜索時,什麼也沒有顯示。我沒有收到錯誤消息。在我的其他一些設備上,例如某些Android或iOS 8.x設備,它確實有效。這個特定的問題設備有1200個聯繫人。任何人都有如何解決的建議?我將粘貼我的代碼的相關部分。雖然也許它更像是一個配置問題?Cordova聯繫人插件不總是顯示聯繫人列表

$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個聯繫人 –

+0

如果插件不能按預期工作,請在issues.cordova.io上提出問題 – jcesarmobile

回答

0

嗨,用這個來保存SD卡中的所有聯繫人並顯示。 (默認科爾多瓦接觸和文件的插件)

 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"); 
       } 
相關問題