Search code examples
cordovaphonegap-pluginsonsen-uibackendless

Get user's contact list and connect it to database on backendless using Onsen UI template


Tried using the "Hello world" Onsen template but using the GetContacts function all I got were "number of contacts" and "third contact name".

How do I retrieve the whole contact list?


Solution

  • That template simply demonstrates how to use the cordova api. If you look at the implementation of the function which you mentioned you will see something like:

    function getContacts() {
      var options = new ContactFindOptions();
      options.filter = "";
      options.multiple = true;
      navigator.contacts.find(["displayName", "name"], success, fail, options);
    }
    
    function success(contacts) { 
      alert(contacts.length + ' contacts returned.' + (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted) : ''));
    }
    

    So in your case you can do the same - just instead of showing only the second contact you can do something with all of them:

    function success(contacts) { 
      for (var i = 0; i < contacts.length; i++) {
        console.log('contacts[' + i + '] = ' + contacts[i].name && contacts[i].name.formatted);
      }
    }
    

    You may also be interested in the documentation of navigator.contacts.find.

    As for the connecting the info with backendless - you mention it only in the title and haven't properly explained what you want to do. Also retrieving the data and connecting it sound like two different issues to me. For connecting it you can make a separate question where you give more info about what you want to do with the data and maybe show some of your backendless code (if you have any).