This article focuses on how to support SQLite (Web SQL) on the following platforms:
  • Android
  • iOS
  • Windows Phone

Why should a SQLite Plugin used in Cordova?

  • To follow the HTML5 Web SQL API as close as possible.
  • To support Web SQL on Windows Phone.
  • To deal with the same javascript functions on every platform.
  • Fail-safe nested transactions with batch processing optimisations.
  • Keeps sqlite database in a user data location that is known, can be reconfigured, and iOS will be backed up by iCloud.
  • Works with SQLCipher for encryption.

  Limitations of SQLite on Windows Phone

  • Drop table is not working, seems like a bug in the .NET or C# SQLite library. To work around this, empty the table instead of dropping it.
  • A high number of features in C# SQLite are disabled.
  • Missing failure-safe transaction mechanism.
  • Not (yet) working with SQLCipher for encryption.

What do I have to change in my existing applications?

Not much.

Just replace "window.openDatabase" with "window.sqlitePlugin.openDatabase".

Don't forget to take a look at the limitations of Windows Phone Plugin.

How to install the SQLite Plugin

There are so many SQL Plugins available. I choose "lite4cordova", because it supports Cordova 3.x, it is easy to install and it is still in development.
  • https://github.com/lite4cordova/Cordova-SQLitePlugin
  • https://github.com/lite4cordova/Cordova-SQLitePlugin-WP-2013.12
The second project is an extension of "Cordova-SQLitePlugin", because Windows Phone is not working on "Cordova-SQLitePlugin" yet.

Windows Phone 8

If you are starting to develop for Windows Phone, have a look at this article first.

To setup the project, type the following commands in the command line:
$ cordova create hello com.example.hello Hello
$ cd hello
$ cordova platform add wp8
$ cordova plugin add https://github.com/lite4cordova/Cordova-SQLitePlugin-WP-2013.12.git

Remove all files in "hello/www", except "config.xml".
Copy the testfile to "hello/www".

To build the project type the following commands in the command line:
$ cd hello
$ cordova build

Finish! Open and run the project, execute the testfile to see if all works fine.

Android and iOS

To setup the project, type the following commands in the command line:
$ cordova create hello com.example.hello Hello
$ cd hello
$ cordova platform add android
$ cordova platform add ios
$ cordova plugin add https://github.com/lite4cordova/Cordova-SQLitePlugin.git

Remove all files in "hello/www", except "config.xml".
Copy the testfile to "hello/www".

To build the project type the following commands in the command line:
$ cd hello
$ cordova build

Finish! Open and run the project, execute the testfile to see if all works fine.


In the early years of the Internet, it was possible to breach users security by using of JavaScript to exchange information from one website to another that has less reputation.

Therefore, all modern browsers implement the same origin policy that prevents attacks like cross-site scripting.

However, sometimes cross-origin HTTP request is a must-have requirement for a web application. This article will discuss about methods of how to deal with cross-origin HTTP requests. Lets start with some background information.

Origin policy

The algorithm used to calculate the "origin" of a URI (Uniform Resource Identifier) is specified in RFC 6454.

There are two different cases:
  1. Absolute URIs, the origin is the triple {protocol, host, port}
  2. If the URI does not use a hierarchical element as a naming authority (RFC 3986) or if the URI is not an absolute URI, then a globally unique identifier is used.
Two resources are considered to be of the same origin if and only if all these values are exactly the same.

The table below illustrates a check against the URL "http://www.example.com/pages/index.html":
URL to compare Result Why?
http://www.example.com/pages/index2.html ok Same host and protocol
http://www.example.com/pages2/index.html ok Same host and protocol
httpː//username:password@http://www.example.com/pages/index.html ok Same host and protocol
http://www.example.com:8080/pages2/index.html fail Same host and protocol, but different port
https://www.example.com/pages/index.html fail Different protocol
http://sub.example.com/pages/index.html fail Different host
http://example.com/pages/index.html fail Different host
http://www.example.com:80/pages/index.html - (Different port) Depends on the browser implementation


If the policy cannot be applied, the web browser will respond with an exception message, such as the following:

XMLHttpRequest cannot load ...
Cross origin requests are only supported for HTTP.
Uncaught NetworkError: A network error occurred.

Relaxing the same origin policy

Here are some techniques to relax with origin policy:
  • JSONP. If the requirement was to get only the data from a different domain, then a JSONP request is the best choice. JSONP includes external data via the <script> tag.
  • Cross origin resource sharing. This extends HTTP with a new origin request header and a new Access-Control-Allow-Origin response header. This article describes how to enable CORS.
  • Disable web security (for development mode only). If an application is under development, the web security can temporarily disabled for the web browser. While the web browser is in an unsecured mode, it is highly recommended not to surf on public Internet pages (since the browser is vulnerable for all cross site scripting attacks). See "Disable web security for a web browser".
  • Reverse Proxy. A reverse proxy (or gateway), by contrast, appears to the client just like an ordinary web server. No special configuration on the client is necessary. The client makes ordinary requests for content in the name-space of the reverse proxy. The reverse proxy then decides where to send those requests, and returns the content as if it was itself the origin. See "Setup a reverse proxy".
  • Whitelist (PhoneGap). If a web application is deployed to a mobile device with PhoneGap the domain can whitelisted (Whitelist Guide).

Disable web security for a web browser

For Google Chrome, the following command must executed in Terminal (browser must be closed):

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security

Setup a reverse proxy

Nowadays there are many http servers on the market, however this article focuses on how to configure a reverse proxy with XAMPP.

Install XAMPP

XAMPP is a free and open source cross-platform web server solution stack package, consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages.

You can download XAMPP here http://www.apachefriends.org/en/xampp.html.

Configure a virtual host

A virtual host gives you the possibility to run several name-based web applications on a single IP address.

Configuring the virtual host on your web server does not automatically cause DNS entries to be created for those host names. You can put entries in your hosts file for local testing.

Make a local host file entry

  1. Open your Terminal.
  2. Type: "sudo vi /private/etc/hosts" to open the host file.
  3. Add the following entry "127.0.0.1 local.app.com" to the end of this file. You can modify this domain name to your needs.
  4. Save the file and close it.

Configure XAMPP

  1. Open your Terminal.
  2. Open the XAMPP virtual host file. "sudo vi /Applications/XAMPP/etc/extra/httpd-vhosts.conf"
  3. Add the following virtual host entry to the end of this file:
<VirtualHost *:80>
  DocumentRoot "/Volumes/workspace/myHtml5App"
  ServerName local.app.com
  ProxyPass       /service.php       http://yourExternalHost.com/communication/service.php
</VirtualHost>

Short explanation:
  • "*:80" Listen for virtual host requests on all IP addresses.
  • "DocumentRoot" Destination of the web application on the filesystem.
  • "local.app.com" Server name, must be the same name as in the host file above.
  • "ProxyPass" Proxy path holds the service address.
Before you restart the server, make a quick check to the httpd.conf file. ("sudo vi /Applications/XAMPP/etc/httpd.conf").

Make sure that the following entries are not commented with a "#"
  • "Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf"
  • LoadModule proxy_module modules/mod_proxy.so
  • LoadModule proxy_connect_module modules/mod_proxy_connect.so
If all is fine, restart your server.

If you call "local.app.com" in your browser, the web application should open. But you will still receive a cross origin policy exception, because your web application still sends the requests to "http://yourExternalHost.com/communication/service.php".

To fix this, replace the URL "http://yourExternalHost.com/communication/service.php" with "local.app.com/service.php" in your web application.


You might want to try to run Cordova with Windows Phone. The first thing that came up when I started with this project was, that the Cordova (PhoneGap) documentation is really lack of information. So I wrote this article to make it easier for you to make a successful and even quicker installation.



Note: This installation guide can be used for both, physical machine and Virtual Machine. There are a lot of Virtual Machine servers available on the market. I decided to focus on VMWare Fusion only, but it is also possible to use software like Parallels.

Before you start

It is very important that you have a 64 bit version of Windows 8 installed, otherwise it will not work.

The Windows Phone simulator relies on Hyper-V, which only comes with Windows 8 64 bit.

In case you did not installed, a evaluation ISO (Windows 8 64 bit) can downloaded at the evaluation center.

Configure the Window 8 installation for WP 8 simulator

The first thing you need to do is to prepare the Windows 8 installation for Windows Phone 8 simulator.

Choose your target system (Virtual Machine or Physical System):

Windows 8 installation on a VM

To make the required Virtual Machine settings, use the VMWare Fusion settings below:




Important:
  • Hyper-V requires at least two cores. Of course, for a better performance you can also set more.
  • You should use 2048mb RAM at the minimum, because not only Windows will consume RAM, also the simulator will consume another 256-512mb of RAM.
You also have to modify the "*.vmx" file. Add the lines below to the end of the vmx file:
  • hypervisor.cpuid.v0 = "FALSE"
  • mce.enable = "TRUE"
  • vhv.enable = "TRUE"
Make sure that you have no duplicate keys in this file.

Windows 8 installation on a physical machine

To be able to run the Windows Phone simulator on a physical Windows 8 machine, you have to enable hardware-assisted virtualisation in the BIOS. For more information, take a look at this article:

Install Microsoft Visual Studio

After the initial Windows 8 configuration you are ready to install Microsoft Visual Studio. Here you have to options:
  1. Using the Visual Studio Express 2012 for Windows Phone edition. This version is free of charge to you, but not recommended by PhoneGap (no templates can be used in the express edition). But since you are able to create PhoneGap projects via CLI, maybe this version is what you are looking for. Go to the Visual Studio Express products.
  2. Installing Visual Studio 2013 Pro / Premium / Ultimate (If you need templates)
In all cases the additional required Windows Phone 8 SDK is already included in the installation package.

Don't forget to enable the WP 8 SDK checkbox while you are installing Visual Studio.

Tip: If you are using VS 2013, Microsoft asks you to authenticate the product with a MS Account. But there is also a way to use the product key. Take a look at this article.

When the installation process of Visual Studio is finished, your computer will be restarted by the installation routine. After the restart, login again, but wait some seconds, the installation process will go on. Wait until you see the "Installation successful" message.

Add the .NET framework directory to the PATH system environment variable

Later on you need the "msbuild.exe" executable your PATH variable. In my case I have to add the following path:
C:\Windows\Microsoft.NET\Framework\v4.0.30319
The path may differ (different version of .NET), so make sure that it matches.

Test the WP 8 simulator

As soon as Visual Studio is completely installed you are able to test the simulator. Open Visual Studio and click on "File" > "New Project".

Go to your preferred language section and select a simple Windows Phone project.

If the project is created, just start the project. The simulator should come up. If the simulator open successfully, you can close Visual Studio. Otherwise follow the further instruction which VS will show to you.

Install Node.js

Those of you who are not familiar with Node.js, Node.js is a platform that is used to build scalable network applications. For more information click here. In this case we use Node.js to install Cordova (PhoneGap).

Just go to http://nodejs.org and install Node.js. The installation process is pretty clear (no custom settings required).
After you installed Node.js, RESTART your computer or Virtual Machine.

Install Cordova

To install Cordova, open "node.js command prompt" and type “npm install -g cordova”.

Fix broken Cordova 3.1.0 version

At the moment Cordova is really a mess. So if you installed the Cordova version above, you have two options: Installing a prior version of Cordova (3.0.x) or fixing the current one.

If you want to fix your current installation, you have to replace the two files in the Cordova installation directory:

~\AppData\Roaming\npm\node_modules\cordova\src\metadata\wp8_parser.js

with

https://github.com/sgrebnov/cordova-cli/blob/181aa1b7e8f3c8b2f7c4db12e1f79d64c26e8b42/src/metadata/wp8_parser.js

and

~\AppData\Roaming\npm\node_modules\cordova\src\platform.js

with

https://github.com/sgrebnov/cordova-cli/blob/181aa1b7e8f3c8b2f7c4db12e1f79d64c26e8b42/src/platform.js

Otherwise you'll receive the following error message when you are creating a Cordova project:

"Error: An error occured during creation of wp8 sub-project. The system cannot find the path specified."

Fix broken Cordova 3.2.0 version

Maybe this error message depends on your type of .NET installation, but with Cordova 3.2.0 I cannot add a WP8 project anymore. The following message is displayed:
The command `msbuild` failed. Make sure you have the latest Windows Phone SDKs installed, AND have the latest .NET framework added to your path (i.e C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319).

To fix this, open "c:\Users\%user%\.cordova\lib\wp\cordova\3.2.0\wp8\bin\check_reqs.js":
Replace:
var msversion = output.match(/Microsoft\s\(R\)\s+Build\sEngine\s[a-z]+\s4\.0\.30319/i);

with:
var msversion = output.match(/\.NET\sFramework\,\sversion\s4\.0/i);
or simply set "var msversion = true;" if you have the right version of "msbuild.exe" in your path variable.

Create the final Cordova project

At this point you are able to build the final Cordova project. As mentioned earlier, I use the CLI of Cordova to create the project, not the Visual Studio templates.
  1. Open the command line and type: "cordova create hello com.example.hello HelloWorld". The first argument specifies a hello directory to be generated for your project. The other two arguments are optional: the com.example.hello argument provides your project with a reverse domain-style identifier, and the HelloWorld provides the application's display text. You can edit both of these values later in the config.xml file.
  2. Open the "hello" folder ("cd hello") which you created above.
  3. Add a WP 8 platform to the current Cordova project. Type "cordova platform add wp8"
  4. Open the Windows Explorer and go to hello/platforms/wp8 and double click on the solution file "*.sln". Microsoft Visual Studio will open with your selected project. Just click the "Run Button" to show up the simulator.

It is a bit tricky to deploy a HTML5 application on a Windows Phone, but I hope this article helps...


Most cookies are disabled by default on Windows Phone. However, here is one workaround to allow cookies. Open Internet Explorer and follow the images below:








After I came back from my last vacation, the first thing I did was updating my system to Mavericks. Of course, I read some recommendations before if it is worse to update or not, but after some researches I thought nothing can go wrong :)

The OS X update itself worked for me like a charm without having any problems, but there was one thing I mentioned first: Java is no more included in OS X 10.9 Mavericks. Ok this was easy to fix. The real problem started after I wanted to build my Sencha Touch application via Sencha CMD.

When I started the Sencha CMD build I received a message, that not the right Ruby version is installed on my system.
[ERR] Detected ruby version 2.0.0 was not less than 2.0. Please install ruby 1.8 or 1.9
After some researches on the web, I found the following information:

  • Ext JS themes use Sass variables whose value are set to "null !default".
  • Sass changed the behavior of such things and broke those themes.
  • Sencha Cmd embeds a version of Sass that is known compatible with Ext JS themes.
  • Ruby 2 changed some API and broke that version of Sass.
So the only solution for my problem was going back to Ruby 1.9 to make my Sencha CMD build working again.

There are a lot of ways to downgrade Ruby, but a very straight forward and easy way by using RVM is described in the following article: http://moduscreate.com/sencha-cmd-not-working-in-os-x-10-9-mavericks/