You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Michael Marchment (JIRA)" <ji...@apache.org> on 2013/02/19 10:49:12 UTC

[jira] [Commented] (CB-2422) iOS 6 Facebook Linked Contact Problem.

    [ https://issues.apache.org/jira/browse/CB-2422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13581164#comment-13581164 ] 

Michael Marchment commented on CB-2422:
---------------------------------------

Here is my code:

[JS]

function onRightNavButton() {
    pickContact()
}


function pickContact(allowsEditing) {
    var options = {
        allowsEditing: allowsEditing
    };
    navigator.contacts.chooseContact(onContactSelected, options);
}


function onContactSelected(id) {
    var options = new ContactFindOptions();
    options.filter = "" + id;
    options.multiple = true;

    var phoneNumbers = [];
    contact.phoneNumbers = phoneNumbers;

    var fields = ["id", "displayName", "phoneNumbers"];
    navigator.contacts.find(fields, onContactFound, onError, options);
}


function onContactFound(contacts) {


    for (var i = 0; i < contacts.length; i++) {
        // display phone numbers

        console.log(contacts.length + " contact(s) found");
        console.log("ID = " + contacts[0].id + ", Name = " + contacts[0].displayName);

        $('#contact-feild-null').hide();
        $('#contact-feild-true').show();
        $('#contact-feild').show();



        // Code will stop here if a linked Facebook Contact. No error message given in console or log... Nothing happens.
        // If it's not a linked Facebook Contact, proceed with awesomeness!




        for (var j = 0; j < contacts[i].phoneNumbers.length; j++) {

            contactsPhoneType = contacts[i].phoneNumbers[j].type;

            contactsPhoneNumber = contacts[i].phoneNumbers[j].value;

            if (contactsPhoneNumber == null && contactsPhoneNumber == 'undefined') {
                onError();

            }

            child = $('#directory-item').clone().show();
            $(child).find('input[name=id]').val(contacts[0].id);
            $(child).find('.js-output-tel').attr("href", contactsPhoneNumber);
            $(child).find('.js-output-name').html($(child).find('.js-output-name').html() + ' ' + contacts[0].displayName);
            $(child).find('.js-output-teltype').html($(child).find('.js-output-teltype').html() + '' + contacts[0].contactsPhoneType);
            $(child).find('.js-output-tel2').html($(child).find('.js-output-tel2').html() + ' ' + contacts[0].contactsPhoneNumber);
            $(child).appendTo('.directory-output');

            SaveItems()
        }

        console.log("ID = " + contacts[0].id + ", Name = " + contacts[0].displayName + ", " + contactsPhoneType + " = " + contactsPhoneNumber);



        //Function of saving items to localStorage
        function SaveItems() {
            //Run if validation didn`t fail
            if (validate()) {
                item = {
                    id: contacts[0].id,
                    name: contacts[0].displayName,
                    tel: 'tel:' + contactsPhoneNumber,
                    tel2: contactsPhoneNumber,
                    teltype: contactsPhoneType,
                    relationship: $('.js-output-relationship').find().text()
                };
                //Read and parse current items array
                if (storage['contact'] != undefined) {
                    obj = storage['contact'];
                    contact = JSON.parse(obj);
                }
                //If not exists create empty array
                else {
                    contact = [];
                }
                if ($('#directory-item').find('input[name=id]').val() == '') {
                    //If id undefined push new item to array and save it to a localstorage
                    contact.push(item);
                } else {
                    //Else save to chosen record
                    contact[$('#directory-item').find('input[name=id]').val()] = item;
                    $('#directory-item').find('input[name=id]').val('');
                }
                save = JSON.stringify(contact);
                storage['contact'] = save;
                location.reload();
            }
            return false;
        }

        // }
    }

}
                
> iOS 6 Facebook Linked Contact Problem.
> --------------------------------------
>
>                 Key: CB-2422
>                 URL: https://issues.apache.org/jira/browse/CB-2422
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>         Environment: Present on iOS 6.
> I'm using Phonegap 2.2.0.
>            Reporter: Michael Marchment
>            Assignee: Shazron Abdullah
>              Labels: contacts, facebook, ios, ios6
>
> I've just written an app that uses the (undocumented) "navigator.contacts.chooseContact", which when a contact was selected, would pull their id, displayName & phoneNumbers and arrange them nicely into a table -- BUT! I started to realise that I wasn't adding every contact.
> "console.log(contacts.length + " contact(s) found");" would tell me a contact was there and that there is a contact being chosen, it just (for whatever reason) chooses to ignore the phone numbers and spit out an error. If I remove "for (var j=0; j<contacts[i].phoneNumbers.length; j++) {" and any reference to calling, say, "contactsPhoneNumber = contacts[i].phoneNumbers[j].value;" and calling "contactsPhoneNumber", the function will work! (Code is identical to that in the Phonegap documentation)
> The issue happens when a contact is automatically linked with Facebook. Facebook doesn't always syc phone numbers to the contact as some people don't put them up, but it will syc it with contacts with matching names to friends in your address book.
> For instance, my sister's name is Jessica in my address book but her Facebook name is Jesska so there are 2 contacts in my address book. Phonegap will only insert Jessica, not Jesska even though both have the same phone number.
> Using native code is not my forte, so I thought I might just bring this up here and see if people are having troubles with phone numbers when doing the same thing and perhaps someone who knows native code well could come up with a solution for the next release of Phonegap... If you follow :)
> Thanks all,
> Michael.
> Update: After writing all of this out and double checking to see if it worked, iOS put back in all of the facebook info. I just deleted the linked facebook contact permanently and it worked for that contact again.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira