I'm trying to accomplish a very simple task: Look up a contact by phone number!
If I use the contact picker, JSON.stringify the result I get the following record:
{"id":490,"rawId":null,"displayName":null,"name":{"givenName":"Dufus","formatted":"Dufus Cofefe","middleName":null,"familyName":"Cofefe","honorificPrefix":null,"honorificSuffix":null},"nickname":null,"phoneNumbers":[{"type":"iphone","value":"(123) 456-7890","id":0,"pref":false},{"type":"work","value":"(012) 345-6789","id":1,"pref":false}],"emails":[{"type":"home","value":"dufus....@gmail.com","id":0,"pref":false},{"type":"work","value":"dufus....@domain.com","id":1,"pref":false}],"addresses":[{"postalCode":"33486","type":"home","id":0,"locality":"Boca Raton","pref":"false","streetAddress":"123 Any Street\n","region":"FL","country":"United States"}],"ims":null,"organizations":[{"name":"TestTube","title":null,"type":null,"pref":"false","department":null}],"birthday":null,"note":null,"photos":[{"pref":"false","value":"/var/mobile/Containers/Data/Application/420C5871-1ABC-4BE5-83B2-10A74A94AB09/tmp/contact_photo_490","type":"url"}],"categories":null,"urls":[{"type":"work","value":"http://www.domain.com","id":1,"pref":false}]}
If I search using the following code using various forms of the number as it's returned by the picker I get NOTHING!:
function findContact(phone)
{
var options = new ContactFindOptions();
// options.filter = phone;
// options.filter = "333-333-3333"; // returns "Sandy" in the simulator - this WORKS!
// the iOS record we want as it is returned by the picker is formatted as (123) 456-7890
options.filter = "(123) 456-7890"; // doesn't work
options.filter = "123-456-7890"; // doesn't work
options.filter = "(123)456-7890"; // doesn't work
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name, navigator.contacts.fieldType.phoneNumbers];
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.phoneNumbers, navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, ContactOnSuccess, ContactOnError, options);
}
The success callback is called with a length of zero and no data.
Has anyone figured out how to accomplish this extremely simple task?
Thanks,
P.