Ricky
Ricky

Reputation: 883

Why does WebSQL not work with iOS applications made with PhoneGap?

I just ported my PhoneGap application into the iOS platform, it would seem that the iPad I'm testing on (as well as the simulators provided by xCode) do not want to work properly with WebSQL...

I've chased the issue down to the root, I think. Essentially when I try to open/create the database the app just hangs and doesn't continue past this point...

Here's my clip of my code...

var SQLAPI = function()
{
    self.Init = function()
    {
        // DB Name, Verion Number, Text Description, Estimated Size of DB
        var size = 1000 * 1024 * 1024;
        if(IsMobile())
        {
            document.addEventListener("deviceready", function()
            {
                alert("Started Device Ready");
                self.db = window.openDatabase("MyDB", "1.0", "My Database", size);
                alert("Started Made DB");
                alert("Started DB");
            }, false);
        }
        else
        {
            self.db = window.openDatabase("MyDB", "1.0", "My Database", size);
            alert("started DB 2")
        }
    };
};

The problem arises at the following code...

alert("Started Device Ready");
self.db = window.openDatabase("MyDB", "1.0", "My Database", size);
alert("Started Made DB");
alert("Started DB");

The first alert saying "Started Device Ready" is fired, so an alert box appears saying that text.

It then tries to run window.openDatabase and something happens at this point because it will not execute the next set of alerts ever....

The app works on Browsers, Android devices, etc... It's just on iOS that this issue happens.

Upvotes: 2

Views: 5404

Answers (1)

DaveAlden
DaveAlden

Reputation: 30366

It's probably not working on iOS because you're requesting a database size which far exceeds the allowed limit: 1000 * 1024 * 1024 == 1Gb

The established upper limit for a WebSQL DB in an iOS WebView is 50Mb (see here].

It may work on other platforms either because they allow unlimited size or if requested size is greater than the limit, they cap it to that limit.

Try reducing the size of the DB to below 50Mb e.g. 49*1024*1024

If you need a database with larger capacity than this, consider using something like this native SQLite plugin as a drop-in replacement for WebSQL with unlimited storage capacity.

Upvotes: 3

Related Questions