Friday, October 4, 2013

Instalation of Cordova/PhoneGap SQLitePlugin to iOS PhoneGap Project.

Step 1 -  Goto the Cordova-SQLitePlugin Github Page and download the project (Cordova-SQLitePlugin-master.zip)

Step 2 - Create your PhoneGap project and open it in Xcode.

Step 3 - Goto the "Build Phases" of you Xcode project -> Click the dropdown "Link Binary with Libraries" and add libsqlite3.dylib or libsqlite3.0.dylib.

Step 4 - Unzip the file "Cordova-SQLitePlugin-master.zip" goto the folder src/ios/  you will find SQLitePlugin.h and SQLitePlugin.m file there.

Step 5 - Drag those files to the plugin folder in your Xcode project.  Make sure that you tick the "copy items to destination folder.

Step 6 - Same way you should add the following files to the js folder in Xcode project.


* lawnchair.js  
* SQLitePlugin.js 
* Lawnchair-sqlitePlugin.js

Step 7 - Include these files in the index.html of your project.  Use the code below.

     <script type="text/javascript" src="js/Lawnchair-sqlitePlugin.js"></script>
     <script type="text/javascript" src="js/lawnchair.js"></script>
     <script type="text/javascript" src="js/SQLitePlugin.js"></script>

Step 8 - Add the following code between you <head> </head> tag.
 <script type="text/javascript" charset="utf-8">  
       // Wait for Cordova to load  
       document.addEventListener("deviceready", onDeviceReady, false);  
       // Cordova is ready  
       function onDeviceReady() {  
         console.log("Run1");  
         var db = window.sqlitePlugin.openDatabase({name: "MYDB"});  
         db.transaction(function (tx) {  
                 tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');  
         });  
         db.transaction(function (tx){  
                 for (var index = 1; index < 10; index++){  
                   tx.executeSql('INSERT INTO LOGS (id,log) VALUES ('+index+', '+index+')');  
                 }  
         });  
       }  
     </script>  


Step 9 -   Include the following in your config file.
 <feature name="SQLitePlugin"> 
    <param name="ios-package" value="SQLitePlugin" /> 
 </feature>  

Step 10 - Run your project. Open FInder and goto ->User->Library->Application Support->iPhone Simulator->7.0 -> Applications -"Your Application" -> Documents if you find a file named MYDB.Sqlite then try to open it using some SQLite DB Manager. (I use a Mozilla Firefox plugin named SQLite Manager) Done !!!

12 comments:

  1. In Documents Folder Database is not created Help me out!!!!!!!

    ReplyDelete
    Replies
    1. Could you please elobarate your trouble in detail ? Any error message in console? Did you tried placing some logs to check the execution ?

      Delete
    2. Successfully i created a project and ios phonegap using command prompt. then i download Cordova-SQLitePlugin in Github Page... in xcode build phase i add that link library then i copy .h and .m files in plugin folder and similar like other 3 js files in index.html i edit and add ur code in config file i adder ur feature tag also after successful build using window+shift+g i moved my project directory but in documents folder sqlite file not created there

      Delete
  2. u have any source code copies for this concept means send that to the below mail id prithivi@meliosystems.com or else the detail explanation how to implement sqlite database in phonegap ios...... and one thing i have sql db manager firefox plugin also

    ReplyDelete
  3. Hi dude its Worked... I want to know some other interesting experiments in phonegap

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Can u provide same tutorial for android..??
    Instalation of Cordova/PhoneGap SQLitePlugin to Android PhoneGap Project.

    ReplyDelete
  6. hello, am using ios 6.1 , but there is no config file to add the sqliteplugin.How can i do that & it stating the error "Plugin 'SQLitePlugin' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist."

    Please help me

    ReplyDelete
  7. Cominform is your partner for efficient, custom-tailored business software-solutions. The Cominform team develops on innovative platforms and in line with cutting-edge standards. Here are options for Web Desktop,Web-Desktop, SAML Cordova Plugin , SQL Cordova Plugin , SAML Phonegap Plugin and SQL Phonegap Plugin.

    ReplyDelete
  8. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Mobile App Development Company in Chennai
    Android app Development Company in Chennai
    ios app development Company in Chennai

    ReplyDelete