I’ve been working with the $cordovaContacts plugin in order to grab all of the contacts from a device and then I do a filter later so a user can search for a contact’s name and have their email show up. I have this working on my own iOS and android devices, both when installing directly from my computer and through test flight and google play, however it doesn’t seem to be working for some of my beta testers.
They get a message the first time they install it asking for permission to access their contacts but when they actually try to search for something, the results are blank. They have confirmed with me that they do have contacts with emails that they are trying to search for. Here is my load contacts function:
(I switched from $cordovaContacts to navigator.contacts after $cordovaContacts didn’t appear to be working, but they should work the same to my understanding)
function loadContacts(){
$ionicLoading.show({
template: ‘Loading Contacts…’
});
var options = new ContactFindOptions();
options.filter = “”;
options.multiple = true;
var fields = ["*"];
navigator.contacts.find(fields, onSuccess, onError, options);
}
onSuccess function:
function onSuccess(allContacts){
self.contacts = allContacts;
self.contacts.forEach(function(contact){
if(contact.emails != null){
var name = contact.name.formatted;
var email = contact.emails[0];
var contact = { name: name, email: email.value};
self.emails.push(contact);
}
})
$ionicLoading.hide();
}
onError:
function onError(err){
console.log(“error:”, error);
}
And my search functions are:
function search(){
if(self.data.searchParam != “”){
self.searchContacts(self.transferEmail).then(function(results){
self.list = results;
});
}else{
self.list = ‘’;
}
}
function searchContacts(searchFilter) {
var deferred = $q.defer();
if(searchFilter != “” ){
var matches = self.emails.filter( function(email) {
if(typeof email.name != ‘undefined’){
if(email.name.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1
|| email.email.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1 ) return true;
}
})
}else{
var matches = {};
}
$timeout( function(){
deferred.resolve( matches );
}, 100);
return deferred.promise;
};
Any feedback on what could be going wrong would be awesome