App Crashing on contact.save() when using ID - Apache Cordova
NickName:Gary McNeill Ask DateTime:2015-06-11T06:05:10

App Crashing on contact.save() when using ID - Apache Cordova

Edit: I have tried this on multiple APIs and also an actual android device and it still crashes on save.

I'm developing a contact based app on android using Tools for Apache Cordova for Visual Studio and the cordova contacts plugin (v2.13). I can currently save and retrieve contacts but I cannot UPDATE a contact. I am using the genymotion emulator. and the devices native contact list.

You are supposed to be able to update a contact by passing in the a contact ID that already exists.

I have the contact object and all the fields are being populated but the app just crashes with no error messages when I try to save it.

I am aware this WAS an issue in contacts v1.3 and lower but it has been marked as resolved on their issues list.

Contact Issue Resolution Documentation

Here is a screenshot of my object and also the full AngularJS code

Object Image

droidSync.controller('managerController', function ($scope) {

    //Initialize model
    $scope.contact = {};

    // Create a new contact
    $scope.createContact = function () {
        // Contact Object
        contact = navigator.contacts.create();
        $scope.saveContact();
    };

    // Pick Contact from Device
    $scope.editContact = function () {
       contact = navigator.contacts.pickContact(function(contact){
            console.log(contact);

            //This only updates the text fields. It does not actually assign new values to the object
            $scope.$apply(function () {
                $scope.contact.firstName = contact.name.givenName;
                $scope.contact.lastName = contact.name.familyName;
                $scope.contact.mobileNo = contact.phoneNumbers[0].value;
                $scope.contact.homeNo = contact.phoneNumbers[1].value;
                $scope.contact.email = contact.emails[0].value;
                $scope.contact.id = contact.id;
            });
        })
    };

    // Delete Contact from Device
    $scope.deleteContact = function () {

        //Delete Function Here

    };

    $scope.saveContact = function () {

        var contact = navigator.contacts.create();

        if ($scope.contact.id !== "undefined") {
            contact.id = $scope.contact.id;
        }

        // Display Name and Email
        contact.displayName = $scope.contact.firstName;
        contact.nickname = $scope.contact.lastName;

        var emails = [];
        emails[0] = new ContactField('work', $scope.contact.email, true)
        contact.emails = emails;

        // Phone Numbers
        var phoneNumbers = [];
        phoneNumbers[0] = new ContactField('mobile', $scope.contact.mobileNo, true); // preferred number
        phoneNumbers[1] = new ContactField('home', $scope.contact.homeNo, false);
        contact.phoneNumbers = phoneNumbers;

        // Names
        var name = new ContactName();
        name.givenName = $scope.contact.firstName;
        name.familyName = $scope.contact.lastName;
        contact.name = name;

        // save to device
        contact.save();
    }
});

droidSync.controller('settingsController', function ($scope) {

});

Copyright Notice:Content Author:「Gary McNeill」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30768115/app-crashing-on-contact-save-when-using-id-apache-cordova

More about “App Crashing on contact.save() when using ID - Apache Cordova” related questions

App Crashing on contact.save() when using ID - Apache Cordova

Edit: I have tried this on multiple APIs and also an actual android device and it still crashes on save. I'm developing a contact based app on android using Tools for Apache Cordova for Visual Stu...

Show Detail

Cordova / Kendo app crashing log

I have an app that is crashing from time to time when it starts (Android/IOS). Where can I find a Log on the device so I can understand whats going on. Device: Android / IOS Type: Hybrid -Cordova/...

Show Detail

Cordova App keep crashing on Android device when build in release

Hej Guys I have developed a cordova crossplatform app which if build in debug works fine but when build in release the app keeps crashing. Following are the versions I am using. Cordova-cli: 8.0.0

Show Detail

Apache Cordova App

I did an app for Android using Apache Cordova I came to the end that the program worked fine, but when I put the program on the tablet does not work, would you tell me why? The function of this app...

Show Detail

unable to create android app using apache cordova

I tried to create android app using Apache Cordova using the following command C:\Users\krishna\cordova-3.0.0\cordova-android\bin> create C:\Users\krishna\workspace3\SampleApp2 com.example.

Show Detail

General issues when using dojo app in cordova

i have a normal rich internet application which is running well in each browser, using dojo toolkit and some javascript charting library. I want to put to make it a hybrid app on an ipad for "offl...

Show Detail

Developing iOS app using apache cordova in windows 8

The majority of tutorials I saw online were showing apache cordova iOS app development on OS X needing XCode and stuff. Is it possible to build an app in Apache Cordova and then compile it for diff...

Show Detail

Cordova app with targetSdkVersion 26 crashing on Android 8

I recently updated my Cordova (Meteor) app to target sdk version 26. Since the first day, the app started crashing on some of my users' devices with Android 8.0 and 8.1. One user reported that the...

Show Detail

Apache Cordova and bluetooth

Does Apache Cordova have the abilty to use the mobile device's bluetooth. I'm currently making an app on Android and it uses bluetooth but I would also like to make the same app on Apache Cordova a...

Show Detail

App crashing on using captureImage method of media-capture cordova plugin in my android device

This is my ionic info… cli packages: (/usr/lib/node_modules) @ionic/cli-utils : 1.19.2 ionic (Ionic CLI) : 3.20.0 global packages: cordova (Cordova CLI) : 8.0.0 local packages: enter code her...

Show Detail