Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228603

$localStorage can't be loaded in some cells

$
0
0

Hello everybody I have a problem a long time and decided to post , on some devices(more common 4.1-4.4 no sdcard) $localStorage it is not loaded(already tried use SQLiete, File), but I believe he can save when you authentication because there is application cache. I am weeks for reply but i can not know what the problem is , I can not find solution.

OBS [1]: I've done several tests on my phone ( it works ) by removing the sdcard , but this is not the problem the application works normally.

[2] When installed on an emulator android 4.1 without SDCARD , I encounter the following error in CMD " rm failed for -f , Read only file system"

[3] Already I checked in AndroidManifest and permissions are correct

My permissions: whitelist camera media-capture device statusbar file file-transfer imagepicker media network-information file-opener2 sqlite-storage ms-adal x-toast socialsharing.

My routine is: CHECKS(READ) localStorage ->

IF OK : AUTH AUTOMATIC -> UPDATE LOCALSTORAGE -> GO HOME PAGE.

ELSE : USERS INFORMATION LOGIN AND PASSWORD -> AUTH -> SAVE LOCALSTORAGE -> GO HOME PAGE.

Look my code:

app.factory('Auth', function ($http, $q) {
    loginAuth = function (login, pswd) {
        var def = $q.defer();
        var url = "XXXXXXXXXXX";
        var uuid = device.uuid;
        $http({
            method: 'GET',
            dataType: "json",
            url: url + 'GetLoginUser',
            params: { login: login, pswd: pswd, cdUuid: uuid }
        }).success(function (data) {
            def.resolve(data);
        }).error(function (data) {
            def.reject("error");
        });
        return def.promise;
    };

    return {
        Login: function (login,pswd) {
            return loginAuth(login, pswd);
        }
    };
});


app.factory('User', function ($cordovaSQLite, $localStorage,$q) {

    var user = {
        idUser: '',
        name: '',
        email: '',
        pswd: '',
        imgProfile: ''
    };

    setUser = function (objUsuario) {
        user.idUser = objUsuario.idUsuario;
        user.name = objUsuario.nome;
        user.email = objUsuario.email;
        user.pswd = objUsuario.senha;
        user.imgProfile = objUsuario.imgProfile;
    };

    deleteUser = function () {
     delete $localStorage.user;
    };

    return {
        Set: function (data) {
            setUser(data);
        },
        Get: function () {
            return user;
        },
        Delete: function () {
            deleteUser();
        }
    };
});





app.controller('LoginCtrl', function ($scope, $ionicLoading, $timeout, $state, $ionicPopup, $http, $localStorage,Auth, UtilApp, User) {
    $scope.user = {
        login: "",
        pswd: ""
    }

    $scope.checkUser = function () {
        UtilApp.Show();
        try {
            if (angular.isDefined($localStorage.user)) {
                Auth.Login($localStorage.user.email, $localStorage.user.pswd).then(function (data) {
                    try {
                        $localStorage.user = data;
                        User.Set($localStorage.user);
                        UtilApp.Hide();
                        $state.go('app.feed');
                    } catch (err) {
                        UtilApp.Hide();
                        UtilApp.AlertShow('ERRO', 'XXXXXXXXXX');
                    }
                },
                function (data) {
                    UtilApp.Hide();
                    if (UtilApp.CheckConnection() == "0") {
                        UtilApp.AlertShow('XXXX', 'XXXXXXX.');
                    } else {
                        UtilApp.AlertShow('XXXX', data.Message);
                    }
                });
            } else {
                UtilApp.Hide();
            }
        }
        catch (err) {
            UtilApp.Hide();
        }

    };

    $scope.logar = function () {
        UtilApp.Safe($scope, function () {
            UtilApp.Show();
            var login = $scope.user.login;
            var pswd = $scope.user.pswd;
            if (login.trim() && pswd.trim() != "") {
                Auth.Login(login, pswd).then(function (data) {
                    try {
                        $localStorage.user = data;
                        User.Set($localStorage.user);
                        UtilApp.Hide();
                        $state.go('app.feed');
                    } catch (err) {
                        UtilApp.Hide();
                        UtilApp.AlertShow('XXXX', 'XXXXXX');
                    }
                },
                function (data) {
                    UtilApp.Hide();
                    if (UtilApp.CheckConnection() == "0") {
                        UtilApp.AlertShow('xxxxxxxx', 'XXXXXXXXXXX');
                    } else {
                        UtilApp.AlertShow('XXXX', data.Message);
                    }
                });

            } else {
                UtilApp.Hide();
                UtilApp.AlertShow('XXXXXX', 'XXXXXXXXXXXXXXXX');
            }
        });

    };

     setTimeout($scope.checkUser(), 10000);

});

Thank you in advance


Viewing all articles
Browse latest Browse all 228603

Trending Articles



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