Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Problems with the LocalStorage of the telephone

$
0
0

@marvinug wrote:

It turns out that when the user registers or loguea I store the token in the storage to validate which screen I should direct it to, what happens is that the computer works for me but not on the device.
When I do the tests in Xcode I load the page first and then it tells me that if there is a token but as first charge the page does not validate the token, I am subscribed to a promise and even then it does not work for me.
Thanks in advance

My Services… Save

guadarStorage(token, id_usuario, nombreUsuario) {
  // Verificamos desde donde se esta haciendo uso de la aplicación en un dispositico o en una computadora
    console.log("Datos a guardar:", this.token, this.id_usuario, this.nombreUsuario);
    console.log(this.token);
  if( this.platform.is( "cordova" ) ) {
    // Estamos en un dispositivo 
    this.storage.set( 'token', token );
    this.storage.set( 'id_usuario', id_usuario );
    this.storage.set( 'nombre', nombreUsuario );
    console.log("Datos guardados");
  }
  else {
    // Estamos en una computadora
    if(this.token) {//Guardamos
      localStorage.setItem( 'token', token  );
      localStorage.setItem( 'id_usuario', id_usuario  );
      localStorage.setItem( 'nombre', nombreUsuario  );
    }
    else {// Borramos
    localStorage.removeItem('token');
    localStorage.removeItem('id_usuario');
    localStorage.removeItem('nombre');
    }
  }
}

My Services… load

cargarStorage() {
  let promesa = new Promise ( ( resolve, reject )=>{
    // Cargar desde el Storage
    if(this.platform.is( "cordova" )) {
      // Estamos en el dispositivo
      this.storage.ready()
                  .then ( ()=>{
                    console.log("que putas esta pasando");
                      // Aquí ya podemos leer del Storage
                      this.storage.get( 'token' )
                                  .then( token => {// Resivo lo que vienes en los items
                                      if ( token ) {// Verifico que venga algo diferente de nulo o undefine
                                        this.token = token;
                                        console.log("Si habia token", this.token);
                                      }
                      })
                      // Aquí ya podemos leer del Storage
                      this.storage.get( 'id_usuario' )
                                  .then( id_usuario => {// Resivo lo que vienes en los items
                                      if ( id_usuario ) {// Verifico que venga algo diferente de nulo o undefine
                                        this.id_usuario = id_usuario;
                                      }
                      })
                      this.storage.get( "nombre" )
                                  .then( nombre => {// Resivo lo que vienes en los deseos
                                      if ( nombre ) {// Verifico que venga algo diferente de nulo o undefine
                                        this.nombreUsuario = nombre;
                                      }
                      })
                  })
    }
    else {
        // Estamos en la computadora
        if( localStorage.getItem( 'token' ) ) {
          // Si entra existen items en el localStorage
          this.token = localStorage.getItem( 'token' );
          this.id_usuario = +localStorage.getItem( 'id_usuario' );
          this.nombreUsuario = localStorage.getItem( 'nombre' );
        }
    }
    resolve();
  });
  return promesa;
}

My App.componet


      this.usersProv.cargarStorage()
                    .then( ()=>{
                      console.log("Iniciando app...")
                      console.log(this.usersProv.token)
                      console.log("------------------------")
                      if(this.usersProv.token){//Validamos que tenga token y asi lo redireccionamos
                        this.rootPage = MapaPage;
                      } else {
                        this.rootPage = HomePage;
                      }
                      // Okay, so the platform is ready and our plugins are available.
                      // Here you can do any higher level native things you might need.
                      this.statusBar.styleDefault();
                      this.splashScreen.hide();
                    });

my code Xcode

2018-06-28 09:50:16.795639-0600 Carbox Drive[4794:72157] Ionic Native: deviceready event fired after 1618 ms
2018-06-28 09:50:16.797417-0600 Carbox Drive[4794:72157] I**niciando app...**
**2018-06-28 09:50:16.797698-0600 Carbox Drive[4794:72157] **
**2018-06-28 09:50:16.797972-0600 Carbox Drive[4794:72157] ------------------------**
2018-06-28 09:50:16.798845-0600 Carbox Drive[4794:72157] WARN: Native: tried calling StatusBar.styleDefault, but the StatusBar plugin is not installed.
2018-06-28 09:50:16.799079-0600 Carbox Drive[4794:72157] WARN: Install the StatusBar  plugin: 'ionic cordova plugin add cordova-plugin-statusbar'
2018-06-28 09:50:16.805027-0600 Carbox Drive[4794:72157] que putas esta pasando
2018-06-28 09:50:16.808352-0600 Carbox Drive[4794:72157] OPEN database: _ionicstorage
2018-06-28 09:50:16.808798-0600 Carbox Drive[4794:72157] -[SQLitePlugin pluginInitialize] [Line 29] Initializing SQLitePlugin
2018-06-28 09:50:16.809123-0600 Carbox Drive[4794:72157] -[SQLitePlugin pluginInitialize] [Line 40] Detected docs path: /Users/desarrollomktech/Library/Developer/CoreSimulator/Devices/0000429C-9A64-412D-B686-AB0B8A4A72A6/data/Containers/Data/Application/520D0CB0-48E7-495D-8FC9-AD86C30D0AAB/Documents
2018-06-28 09:50:16.809285-0600 Carbox Drive[4794:72157] -[SQLitePlugin pluginInitialize] [Line 44] Detected Library path: /Users/desarrollomktech/Library/Developer/CoreSimulator/Devices/0000429C-9A64-412D-B686-AB0B8A4A72A6/data/Containers/Data/Application/520D0CB0-48E7-495D-8FC9-AD86C30D0AAB/Library
2018-06-28 09:50:16.809475-0600 Carbox Drive[4794:72157] -[SQLitePlugin pluginInitialize] [Line 51] no cloud sync at path: /Users/desarrollomktech/Library/Developer/CoreSimulator/Devices/0000429C-9A64-412D-B686-AB0B8A4A72A6/data/Containers/Data/Application/520D0CB0-48E7-495D-8FC9-AD86C30D0AAB/Library/LocalDatabase
2018-06-28 09:50:16.809892-0600 Carbox Drive[4794:72405] -[SQLitePlugin closeNow:] [Line 203] close: db name was not open: _ionicstorage
2018-06-28 09:50:16.809967-0600 Carbox Drive[4794:72157] new transaction is queued, waiting for open operation to finish
2018-06-28 09:50:16.853405-0600 Carbox Drive[4794:72157] WARN: 
    It looks like you're using ngModel on the same form field as formControlName. 
    Support for using the ngModel input property and ngModelChange event with 
    reactive form directives has been deprecated in Angular v6 and will be removed 
    in Angular v7.
    
    For more information on this, see our API docs here:
    https://angular.io/api/forms/FormControlName#use-with-ngmodel
2018-06-28 09:50:16.943398-0600 Carbox Drive[4794:72349] -[SQLitePlugin openNow:] [Line 141] open full db path: /Users/desarrollomktech/Library/Developer/CoreSimulator/Devices/0000429C-9A64-412D-B686-AB0B8A4A72A6/data/Containers/Data/Application/520D0CB0-48E7-495D-8FC9-AD86C30D0AAB/Library/LocalDatabase/_ionicstorage
2018-06-28 09:50:16.969520-0600 Carbox Drive[4794:72349] -[SQLitePlugin openNow:] [Line 168] Good news: SQLite is thread safe!
2018-06-28 09:50:17.004614-0600 Carbox Drive[4794:72157] OPEN database: _ionicstorage - OK
2018-06-28 09:50:17.004954-0600 Carbox Drive[4794:72157] DB opened: _ionicstorage
2018-06-28 09:50:17.045401-0600 Carbox Drive[4794:72157] **Si habia token b601d5f61ce4ac34f6d04e31135dce1c35a4658c**

In the Xcode opens the home because as it runs it has no token but the token does exist

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>