Page 1 of 1

Cannot save contact to phone

Posted: Wed May 15, 2013 1:21 pm
by w

I have a button with this clickevent:

function onSuccess(contact) {
alert("Save Success");
};

function onError(contactError) {
alert("Error = " + contactError.code);
};

alert("1");
var myContact = navigator.contacts.create({"displayName": "Jane Doe"});
alert("2");
myContact.note = "This contact has a note.";
alert("3");
var name = new ContactName();
name.givenName = "Jane givenname";
name.familyName = "Doe familyname";
myContact.name = name;
alert("4");
contact.save(onSuccess,onError);
alert("5");

I have ALL android permissions checked in the app settings.

The app gives me the alert windows until alert("4"), but doesn't show 5 and doesn't show "save success" or "error". What am I doing wrong?

This is a basic case to add a contact, so I don't know what is wrong.


Cannot save contact to phone

Posted: Wed May 15, 2013 1:47 pm
by Kateryna Grynko

Hi,

On what device are you testing?
What's the OS?


Cannot save contact to phone

Posted: Wed May 15, 2013 2:00 pm
by Kateryna Grynko

Hi!

There is a typo. You have a variable "myContact", but then you use "contact" that is undefined.


Cannot save contact to phone

Posted: Wed May 15, 2013 2:16 pm
by w

My apologies, now it is working.

Is there a way to check for these kind of syntax errors? Because now the code is very short, but what if I have a script of a couple of pages?


Cannot save contact to phone

Posted: Wed May 15, 2013 2:46 pm
by Oleg Danchenkov

Unfortunately not.
Just check errors in Console...


Cannot save contact to phone

Posted: Wed May 15, 2013 2:52 pm
by w

Yes, in firefox, but for things like this (contact.save) , it is a native app, so I don't have a console to log errors I think?


Cannot save contact to phone

Posted: Wed May 15, 2013 3:03 pm
by Oleg Danchenkov

If your code is too big and you can't find error manually then you can download Eclipse/xCode project and debug it in Eclipse/xCode.


Cannot save contact to phone

Posted: Wed May 15, 2013 5:55 pm
by Harold Gottschalk

For Debugging on device.

You can use Weinre Phonegap build provides a cloud version it is a bit slow. I have also used Catalyst from trigger.io it works pretty good and is free to use. Appery.io could provide a similar service since it is all based on Weinre.