PhoneGAP: Ported working code from Android platform to iOS

| | August 6, 2015

I recently finished and committed an offline version of our survey app for Android.

Now the “code” aka the www-directory is being ported to iOS.

I think both AppCode and Xcode are difficult to use – this might be because the debugging is not optimized for web coding.
Last night I spent 1.5 hours looking at a spelling error “serInterval” -> “setInterval”.
This would have been easily recognized by IntelliJ IDEA.

Now I’m stuck in some SQlite code, that should store the answers from the surveys in a local database and sync it to our cloud system, when the device comes online.

I can, via console.log(), see that my functions is running, but nothing is put into my tables.

The code for posting the survey to the local database is:

$(document).ready(function() {
        $('input#submitForm').live('click', function() {
            var formData = $('#questForm').serializeArray();
            var jsonFormData = JSON.stringify($('#questForm').serializeObject());
            jQuery.ajaxSetup({
                beforeSend: function() {
                    $("body").addClass("loading");
                    dbConnect();
                    storeAnswer(uniqueID,readerID,jsonFormData);
                    console.log("Barcode: "+barcode+" VisitorID: "+visitorID+" UniqueID: "+uniqueID+" - "+readerID);
                },
                complete: function(){
                    window.location.href = 'surveyScan.html';
                },
                success: function() {}
            });
            try {
                $.post(null,function(){});
            }
            catch(e) {
                console.error("Error using mycommand: " + e.message);
            }
        });
    });

The log message prints out what I’m expecting…

storeAnswer function:

function storeAnswer(visitor_ID, reader_ID, formData) {
    console.log('storeAnswer()');
    html5sql.process(
        ["INSERT INTO Answers (_id, visitorUID, readerID, json) VALUES (null,'"+visitor_ID+"','"+reader_ID+"','"+formData+"');"],
        function(){
            console.log('Inserted 1 row into table: Answers!');
        },
        function(error, statement){
            console.error("storeAnswer: Error: " + error.message + " when processing " + statement);
        }
    )

}

In the storeAnswer() only the first log message prints (storeAnswer())…

Please let me know if you need other details.

One Response to “PhoneGAP: Ported working code from Android platform to iOS”

  1. In your Xcode preferences downloads components and install the CLI tools
    Then open safari > go to safari >preference >Advanced >Show develop menu in menu bar.

    Now run you app on simulator
    Open safari
    Go to Develop menu > IPhone simulator > you page
    Now you can in the console type
    location.href=”index.html” to reload the page and figure out anything you want.
    Also all phonegap objects will be accessible from here

    For doing custom add n delete in sqlite db
    /Users/username/Library/Application Support/iPhone Simulator/6.1/Applications
    Navigate to the app folder (if the sqlite db is being created there)
    Then do sqlite3 dbname & then try to do your sqlite 3 operations
    The same can then be incorporated in the JS which you can call from the Browser’s Console.

Leave a Reply