Start the app when all native plugin are loaded

Hello everyone, i need to ask a little question…

I used the Native storage plugin in my application, the app has a login, the server give a access token (random hash) to consume other WS, i stored the token with native storage, the problem is that when the app init, the first page consume a WS that need the access token given from storage, but ionic first load the app and then load the plugins in the project, sometimes can show me the flow normal and other times in the console log show me “Plugin no installed: Native Storage” and therefore can not read the stored token

i cant a solution appropietely, only that i can do is do a timeOut, after a time that the app loaded get the token and consume the WS.

I compile in device physical and has the same problem.

how can i start the app only when all plugins native are completility loaded?

Use the ionic native plugin when calling your plugin…

platform.ready().then(() => this.pluginName());
1 Like

I found the problem, it was a some stupid really sorry!.
in app.component.ts i declared rootPage inmediatily, i forgot wrote rootPage:any and in the platform.ready() set the rootPage with the correspond page.

i was do this

rootPage:any = HomePage;

It was obviously that load HomePage and this page tried use the native Storage when the own app won’t load.

Finally the app works correctility

export class MyApp {
  rootPage:any;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,
  public nativeStorage: NativeStorage) {

      platform.ready().then(() => {

        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.

        this.nativeStorage.getItem('accessToken')
          .then(
            access => {
              if(access != undefined){
                statusBar.styleDefault();
                splashScreen.hide();
                this.rootPage = HomePage
                
              }else{
                statusBar.styleDefault();
                splashScreen.hide();
                this.rootPage = LoginPage
              }
            }
          )

      });

  }
}

Thanks, it was my error!.

Thanks for answer, helped that i realized my error.