2012-07-29 62 views
3

现在PhoneGap的是2.0版本,有一个(潜在无证)的方式有一个联系人选择器?PhoneGap的联系人选取

该文档使它看起来像我不得不通过请求用户的所有联系人,然后建设自己的应用程序内联系人选取写我在JavaScript自己。

http://docs.phonegap.com/en/2.0.0/cordova_contacts_contacts.md.html#Contacts

我发现一个一次性的插件为Android,但如果没有插件的iPhone,因为那样我还是写我自己是没有帮助的。我在寻找,说:“让用户去选择一个联系人,然后与该联系人信息回到这里给他们”

回答

1

我不知道你是否可以使用该解决方案为Android以及但是设备无关的方法对于iPhone,您可以使用.chooseContact()方法。

例子:

<a href="#" onclick="contactChooser()">Choose a contact</a> 


    function contactChooser(){ 

    //The chooseContact method will open a new window with all you contacts 
    navigator.contacts.chooseContact(

     //After picking a name you will receive the id of the chosen contact 
     function(id){ 

      //In an options variable you can set some filter parameters 
      //In this example we will use the Id to receive the data of the chosen contact 
      var options = { 
       filter: ""+id 
      } 

      //In the fields variable we're going to set the fields we want to receive 
      //'*' = every data. More field values are explained 
      // here: http://bit.ly/T8YyuE 
      var fields = ['*']; 

      navigator.contacts.find(fields, onPickContactSuccess, onPickContactError, options); 
     }, null); 
    } 

    function onPickContactSuccess(contacts){ 
     //contacts contains all data you've requested 

     var _name = contacts[0].name 

     alert('Last: '+_name.familyName+' First: '+_name.givenName); 
    } 
+0

刚一说明:这似乎是唯一的iOS无证功能。见https://groups.google.com/forum/?fromgroups#!topic/phonegap/JI42d5prb-I – Anthony 2013-05-23 22:41:46

相关问题