javascript - Why is ionicPlatform.ready works randomly? -
i building ionic app , having problems "ionicplatform.ready" method.
i have declared in app.js, @ top :
.run(function($ionicplatform,config) { $ionicplatform.ready(function() { if(window.cordova && window.cordova.plugins.keyboard) { // hide accessory bar default (remove show accessory bar above keyboard // form inputs) // don't remove line unless know doing. stops viewport // snapping when text inputs focused. ionic handles internally // nicer keyboard experience. cordova.plugins.keyboard.hidekeyboardaccessorybar(true); cordova.plugins.keyboard.disablescroll(true); } if(window.statusbar) { statusbar.styledefault(); } firebase.initializeapp({ apikey: config.firebase_api, authdomain: config.firebase_auth_domain, databaseurl: config.firebase_db_url, storagebucket: config.firebase_storage, messagingsenderid: config.firebase_storage }); }); })
now, try log user in (used works super fine until morning decided not work anymore) :
.controller('logincontroller',['$scope', '$ionicloading', '$timeout', '$firebasearray', 'config', '$document', '$state', function($scope, $ionicloading, $timeout, $firebasearray, config, $document, $state) { // perform login action when user submits login form $scope.dologin = function(userlogin) { if($document[0].getelementbyid("user_name").value != "" && $document[0].getelementbyid("user_pass").value != ""){ // setup loader $ionicloading.show({ content: 'loading', animation: 'fade-in', showbackdrop: true, maxwidth: 200, showdelay: 0 }); firebase.auth().signinwithemailandpassword(userlogin.username, userlogin.password).then(function() { var userid = firebase.auth().currentuser.uid; firebase.database().ref('accounts/' + userid + '/currentbusiness/').update({ name: "no current business arround", description: "seems there's nothing arround...", }) $state.go("tab.account"); }, function(error) { // error happened. var errorcode = error.code; var errormessage = error.message; if (errorcode === 'auth/invalid-email') { alert('enter valid email.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else if (errorcode === 'auth/wrong-password') { alert('incorrect password.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else if (errorcode === 'auth/argument-error') { alert('password must string.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else if (errorcode === 'auth/user-not-found') { alert('no such user found.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else if (errorcode === 'auth/too-many-requests') { alert('too many failed login attempts, please try after sometime.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else if (errorcode === 'auth/network-request-failed') { alert('request timed out, please try again.'); $timeout(function () { $ionicloading.hide(); }, 1000); return false; }else { alert(errormessage); $timeout(function () { $ionicloading.hide(); }, 1000); return false; } }); }else{ alert('please enter email , password'); return false; }//end check client username password };// end $scope.dologin() // create callback logs current auth state firebase.auth().onauthstatechanged(function(user) { if (user) { $state.go("tab.account"); // user signed in. } else { // no user signed in. } }); }])
now, doesn't work on devices (works on browser) unless call in controller :
var isandroid = ionic.platform.isandroid(); if(isandroid) { firebase.initializeapp({ apikey: config.firebase_api, authdomain: config.firebase_auth_domain, databaseurl: config.firebase_db_url, storagebucket: config.firebase_storage, messagingsenderid: config.firebase_storage }); }
also, if later sign out of app, doesn't want come on login page because says there 2 times initialization of app (once in run , once in controller).
what missing ?
Comments
Post a Comment