Skip to content

Instantly share code, notes, and snippets.

@tkh44
Last active December 21, 2015 09:58
Show Gist options
  • Select an option

  • Save tkh44/6288430 to your computer and use it in GitHub Desktop.

Select an option

Save tkh44/6288430 to your computer and use it in GitHub Desktop.
Used instead of sync to pull local contacts.
getContacts: function(filter, cb) {
var fields = ['name', 'emails'],
options = new ContactFindOptions(),
callback = cb || $.noop,
self = this;
options.filter = filter || '';
options.multiple = true;
this.reset();
var onSuccess = function(contacts) {
var self = this;
_.each(contacts, function(contact) {
var name = contact.name,
email;
if (contact.emails) {
email = _.findWhere(contact.emails, {'type': 'work'}) || contact.emails[0];
}
self.add({
firstName: name.givenName || '',
lastName: name.familyName || '',
email: email ? email.value : ''
})
});
callback();
};
var onError = function(error) {
console.log(error);
callback();
};
navigator.contacts.find(fields, _.bind(onSuccess, this), _.bind(onError, this), options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment