Offline ionic app


#1

Hi. i am new to ionic.my requirement is to create a mobile application for an existing website which is created using codeigniter and mysql db.Now my client wants the app to work in offline mode.How to achieve that??.Does it requires firebase / other db for app ??.if so how it syncs with the mysql db of my website ??Thanks in advance… && Sorry for my bad english.


#2

I think you have to use sql lite or local storage. Offline is offline and CI is php so you need a web server to serve it and an internet connection to access the database.

If you need it offline you need to make the database in sqllite or local storage. 2 separate things. If you need it to sync then it needs to be online in order for it to sync. If that is the case, you need the database to output json and your Ionic to make Ajax requests to access the data needed as Ionic is not a serverside technology


#3

By offline i mean that the app has to work well in case there is no network connection not completely offline without server .Consider if offline and user completes a form and submits it has to be saved locally.When connected to network i have to update that to server.How can i achieve that


#4

Look at Angular polling where Angular constantly checks for a connection and if it is $timeout caches the request and sends it when the connection is established.


#5

thanks :slight_smile:


#6

I have tried sqlite.I want the save some common fields from my web db to my mobile db.I got this piece of code from a source…Is it a correct method??.Each time i reload the web the values are inserting into websql db .how can i avoid inserting repeated value??Any other method to sync my live db to device db??

$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {

      StatusBar.styleLightContent();
    }
     
    if (window.cordova) {
    	
        db =  $cordovaSQLite.openDB("test.db");
     
      }else{
    	  
        db = window.openDatabase("test.db", '1', 'ecohub', 1024 * 1024 * 100); // browser
        
      }
    
    	$rootScope.db = db;
    
	    db.transaction(function (tx) {
	    	  		tx.executeSql("CREATE TABLE IF NOT EXISTS gender (gender_id int NOT NULL PRIMARY KEY , gender_name varchar )");
	    		
	    		tx.executeSql("INSERT INTO gender (gender_id,gender_name) VALUES"
	        			+ "(1, 'Male'),(2, 'Female'),(3, 'Others')");
	    		
	    	
        	tx.executeSql("CREATE TABLE IF NOT EXISTS expense_category (exp_cat_id int ,exp_cat_name varchar)");
        	tx.executeSql("INSERT INTO expense_category (exp_cat_id,exp_cat_name) VALUES"
        			+ "(1, 'Mileage'),(2, 'Travel'),(3, 'Accomodation'),(4, 'Subsistence'),(5, 'Consumables'),(6, 'Others')");
        });
			  
  });

#7

Not too sure on this one…Have you assigned values in the form fields or somethnig? Can’t you make a RESTFUL post request from your form app to your external DB on your server using the $http? If the request is not sent or there is no connection save it as local storage as an object. Use polling to check for a connection, then send it again.

I’m learning Ionic also so you may need to use the post request it to a php CURL script that then connects to your MYSQL, Not too sure on Cross domain either using Ionic


#8

I am making RESTFUL post request from my app to my external DB.i just want to show how i save data using web sql and make sure that i am going in right track :slight_smile: Thanks for the quick response.


#10

@Sujith008 have you found any solution? am also looking for the same.


#11

Hey,
We use PouchDB to achieve a very simple offline first experience and have a Cloudent back end which syncs automagically since its CouchDB based.