Last active
December 21, 2015 09:58
-
-
Save tkh44/6288430 to your computer and use it in GitHub Desktop.
Used instead of sync to pull local contacts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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