3

现在 PhoneGap 是 2.0 版,是否有(可能未记录的)方法来拥有联系人选择器?

这些文档看起来好像我必须通过请求所有用户的联系人来用 JavaScript 编写自己的,然后构建我自己的应用内联系人选择器。

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

我找到了适用于 Android 的一次性插件,但如果没有适用于 iPhone 的插件,那将无济于事,因为我仍然必须自己编写。我正在寻找一种与设备无关的方法,它说“让用户去选择一个联系人,然后用那个联系信息把他们发回这里”

4

1 回答 1

1

I don't know whether you can use this solution for Android as well but for iPhone you can use the .chooseContact() method.

Example:

    <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);
    }
于 2012-09-20T17:27:07.563 回答