Nativescript-contacts save() hangs


I’m working with the nativescript-contacts and native script-permissions plugins to develop some sample code to simply add a contact on Android. Here’s the sample code:

var contacts = require( "nativescript-contacts" );
var permissions = require( "nativescript-permissions" );

exports.onAddContactsTap = function (args) {
    console.log("Add to Contacts tapped");

    var newContact = new contacts.Contact(); = "John"; = "Doe";
    newContact.phoneNumbers.push({ label: contacts.KnownLabel.HOME, value: "123457890" }); 
    newContact.phoneNumbers.push({ label: "CELL", value: "11235813" }); = "My Organization";

        "Permission needed to add volunteers to contacts")
        .then(() => {
            console.log("Permission accepted...");
            console.log("newContact saved.");
        .catch(() => {
            console.log("Error: " + err);

The permissions part works OK, but control is never returned from I tried using a promise on the call, but with no change in results. This is basically the same code listed on the nativescript-contacts page, but after several hours I’m stuck. Any suggestions?


So, I went back to the original sample code from the nativescript-contacts page (i.e., removed the permissions processing). This time, the command still failed, but I could see the error message, “System.err: Error: No Accounts!” So, I added a google account to the emulator, and now the commands work correctly and I can add a contact.

I’m concluding that on a new emulator image, some amount of initial setup is required (e.g., adding an account under Settings/Accounts).

Is it possible to test for this condition so that a meaningful error message can be displayed?


The plugin already does it for you. You just have to wrap your code with a try/catch block to catch that error in a nice way.


manojdcoder - thanks for the info. I’ll add that.