2017-07-15 21 views
1

我想查看所有聯繫人,但navigator.contacts未定義。navigator.contacts未定義

cordova plugin add cordova-plugin-contacts 
cordova build android 
$(document).ready(function(){ 
    $(document).on('deviceready', function(){ 
    alert('something'); 
    }, false); //it doesn't even alert something; 
    console.log(navigator.contacts); 
}); 

我把它拿出來的文件準備無論是。沒有結果:(

有人說這個問題可以通過刪除和添加平臺android並重新添加插件來解決,但它沒有! 我也把腳本標記放到最後,以便頁面加載然後運行腳本

+0

感謝編輯:) – codepro

回答

0

我想這個代碼的某個時候回到我的項目和它的工作:

$(document).ready(function() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
}); 

function onDeviceReady() {  
    $('#contact').click(function() 
     { 
      try {    
       var contact = navigator.contacts.create({"displayName": "CordovaUser"}); 
       var phoneNumbers = []; 
       phoneNumbers[0] = new ContactField('work', '212-555-1234', false); 
       phoneNumbers[1] = new ContactField('mobile', '917-555-5432', true); // preferred number 
       phoneNumbers[2] = new ContactField('home', '203-555-7890', false); 
       contact.phoneNumbers = phoneNumbers;     
       contact.save(); 
       alert("Contact created successfully"); 
      } 
      catch(err) { 
       alert("Plugin Error - " + err.message); 
      } 

     });  
} 
+0

它是創造,但是我想獲取聯繫人用戶。你可以改變它來獲得聯繫人嗎? – codepro

+0

@codepro你在這裏有一個樣本 - https://github.com/apache/cordova-plugin-contacts#navigatorcontactsfind – Gandhi