First Run after app installation

This topic thread is almost identical to another thread: Best way to show first view dynamically when starting app

All the issues and solutions discussed there also apply here.

Anyway, initially I also couldn’t get it working, the trick was to NOT call “$urlRouterProvider.otherwise(…)” when configuring your “$stateProvider”. So, if in your app.js you have something like this:

$stateProvider

      .state('app', {
        url: "/app",
        abstract: true,
        templateUrl: "js/app/menu/menu.html"
      })

      .state('app.auth', {
        url: "/auth",
        abstract: true,
        template: '<ion-view/>'
      });

  // THE STANDARD IONIC STARTER APPS HAVE THIS LINE -
  // REMOVE THIS OR COMMENT IT OUT!
  // $urlRouterProvider.otherwise('/app/playlists');    // commented out

then make sure to REMOVE or COMMENT OUT the “$urlRouterProvider.otherwise(…)” call.

Actually this solution was already discussed in the thread I mentioned:

Best way to show first view dynamically when starting app

1 Like

Hi Leob,

it is working now… also one more i want to show ionicloading.show 2 times

$ionicLoading.show({ template: ‘Please wait…Start Sync…’ })

then code

$ionicLoading.hide()

$ionicLoading.show({ template: ‘sync completed… total user is 20.’ })

then code

$ionicLoading.hide()

first template is not showing

I implemented one for Ionic 2 using local Storage

import { Storage } from '@ionic/storage';
export class App{ 
constructor(public storage:Storage){}
     this.storage.get('launchCount').then(applaunchCount => {
        if (applaunchCount) {
          alert('launch count ' + applaunchCount);
        }
        else {
          alert('launch count '  + applaunchCount);
         this.storage.set('launchCount', applaunchCount);
        }
      });
}

HI . I am getting issue
Invalid shorthand property initializer

i used same thing and put Application in my run ,comment otherwise function . Create factory .what is wrong here ?

Hi
I added the factory ‘Application’ in app.js at the end of the chain and the app.run goes like this:
run(function($ionicPlatform,$state) {

$ionicPlatform.ready(function() {
	// Hide the accessory bar by default (remove this to show the accessory
	// bar above the keyboard
	// for form inputs)
	 <!--if(navigator && navigator.splashscreen) navigator.splashscreen.hide();-->
	if (window.cordova && window.cordova.plugins.Keyboard) {
		cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
		window.cordova.plugins.Keyboard.disableScroll(true);		}
	if (window.StatusBar) {
		// org.apache.cordova.statusbar required
		StatusBar.styleDefault();
	}

})
if (Application.isInitialRun()) {
		//alert("Initial");
       Application.setInitialRun(false);
  		$state.go('prelogin');
  		//$location.path('/loginurl');
	}
    else {
    	//alert("No");
    	//$location.path('/login');
      $state.go('login');
    }

})

The issue is that I am getting a blank white screen when the app is run.Can you please tell me where I have gone wrong?
Thanks in advance,
Sunita

Does it work in “ionic serve” but not on a device? If you run the app on an Android device you should run “adb logcat” to see what is going on, for sure there’s an error stacktrace.

Actually I am coding in Eclipse and testing in emulator.
Now I have shifted the factory ‘Application’ to services,js
This is how the app.js file starts like this:
angular.module(‘starter’,
[ ‘ionic’, ‘starter.controllers’, ‘starter.services’, ‘starter.directives’ ])
services.js is as follows:
angular.module(‘starter.services’, [‘ionic’])

.service(‘CallingService’, function($http) {
return {
. …
};
var loginUrl= localStorage.getItem(“loginurl”);
//alert(loginUrl);
return $http.post(loginUrl,logindata);
}
}
})

.service(‘PerformService’, function($http) {
return {

};
return $http.post(‘http://…’,tagdata);
}
}
})
.factory(‘Application’, function ($window) {
return {
setInitialRun = function (initial) {
$window.localStorage[“initialRun”] = (initial ? “true” : “false”);
},
isInitialRun = function () {
var value = $window.localStorage[“initialRun”] || “true”;
return value == “true”;
}
};
});

The error shown in logcat is:
Error: [$injector:nomod] Module ‘starter.services’ is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Hi Ieob,
I found out the reason for the error:
.factory(‘Application’, function ($window) {
return {
setInitialRun = function (initial) {
$window.localStorage[“initialRun”] = (initial ? “true” : “false”);
},
isInitialRun = function () {
var value = $window.localStorage[“initialRun”] || “true”;
return value == “true”;
}
};
});

The token ‘=’ when replaced with ‘:’ solved the issue.

Ah yes, so “setInitialRun: function” instead of “setInitialRun = function” right?

Because you’re returning an object “{}” and the 2 functions are members (properties) of the object.