Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts


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.


When you want to display your launch screen longer as normal you can do this by simply adding a sleep() in the AppDelegate implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Time in seconds
    sleep(5);
    
    // Override point for customization after application launch.
    return YES;
}
When you want to remove all provisioning profiles from Xcode, close Xcode and run the following commands from terminal:

rm -r ~/Library/MobileDevice/Provisioning\ Profiles/
rm  ~/Library/Developer/Xcode/connect1.apple.com\ 4.6.1.db

Xcode quit unexpectedly.

Click Reopen to open the application again. Click Report to see more detailed information and send a report to Apple.



When you received the message above while refreshing provisioning profiles, close Xcode, go to terminal and delete the "connect1.apple.com 4.6.1.db" file:
rm  ~/Library/Developer/Xcode/connect1.apple.com\ 4.6.1.db
After deleting the database file you should be able to refresh provisioning profiles in Xcode again.
Maybe you received  the following error while building a Sencha Architect application:

Error: The package command has moved to 'sencha app package'

This error is thrown because Sencha Architect 2.1 only works with Sencha Cmd 3.0.0 version.

To fix this you have to download and refer one of the following Sencha Cmd 3.0.0 versions:

http://cdn.sencha.com/senchacmd/SenchaCmd-3.0.0.250-linux-x64.run.zip
http://cdn.sencha.com/senchacmd/SenchaCmd-3.0.0.250-linux.run.zip
http://cdn.sencha.com/senchacmd/SenchaCmd-3.0.0.250-osx.app.zip
http://cdn.sencha.com/senchacmd/SenchaCmd-3.0.0.250-windows.exe.zip


You have an iPhone storyboard and want to support the iPad too? This can be done in a quick way:

  1. Open Xcode
  2. Duplicate the existing storyboard.
  3. Rename them to "MainStoryboard_iPhone.storyboard" and "MainStoryboard_iPad.storyboard"
  4. Right click on the "MainStoryboard_iPad.storyboard" file > "Open as" > "Source code" 
  5. Search & Replace:
    targetRuntime="iOS.CocoaTouch"
    with:
    targetRuntime="iOS.CocoaTouch.iPad"
  6. Done!


Adding new directories to path variable is really simple under Mac OS X. Just follow the next few steps:
  1. Open the Terminal (press + SPACE and type terminal).
  2. Make sure that you are in your home directory
  3. Type:
    echo 'export PATH=YOURDIRECTORY:$PATH' >> ~/.profil
    • Don't forget to replace "YOURDIRECTORY" with your directory string. In example: /opt/local/bin
  4. Re-open the terminal.
The directory you added should be available in the path variable now.