本文整理汇总了TypeScript中@ionic-native/native-storage.NativeStorage类的典型用法代码示例。如果您正苦于以下问题:TypeScript NativeStorage类的具体用法?TypeScript NativeStorage怎么用?TypeScript NativeStorage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NativeStorage类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
this.serverProvider.post(this.storageProvider.serverAddress+"/preventMultiLogin",body).then((res:any)=>{
console.log("res:"+JSON.stringify(res));
if(res.result=="success"){
// move into TabPage
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
//save this.storageProvider.id
this.storageProvider.userInfoSetFromServer(res.userInfo);
//save id information into storage
let id=this.navParams.get("id");
if(id!=undefined){
var encrypted:string=this.storageProvider.encryptValue('id',id);
this.nativeStorage.setItem('id',encodeURI(encrypted));
this.storageProvider.id=id;
}else{
//read id info and then save it into storageProvider
this.nativeStorage.getItem("id").then((value:string)=>{
this.storageProvider.id=this.storageProvider.decryptValue("id",decodeURI(value));
});
}
console.log("move into TbasPage");
this.app.getRootNav().setRoot(TabsPage);
}else{
console.log("move into LoginPage");
// move into loginPage
this.storageProvider.reset();
this.app.getRootNav().setRoot(LoginPage);
}
});
示例2: loginUser
loginUser(){
console.log("Username:" + this.loginForm.value.username);
console.log("Password:" + this.loginForm.value.password);
this.nativeStorage.getItem(this.loginForm.value.username).then(
user => {
console.log("logged in user: "+JSON.stringify(user));
if(this.loginForm.value.password===user.password){
console.log("storing in localstorage: "+user.username)
this.storage.set("username",user.username).then((username)=>{
console.log("stored in local: "+username);
this.storage.set("loggedIn",true).then((loggedIn)=>{
console.log("loggeado "+loggedIn);
});
this.navCtrl.setRoot(ProfilePage);
});
}else{
let alert =this.alertCtrl.create({
title:"Incorrect password",
buttons:['OK']
});
alert.present();
}
}, error => console.error(error)
);
}
示例3:
this.storage.get("username").then((username)=>{
let index= this.favorites.findIndex((favorite)=>favorite.id==id);
this.favorites.splice(index,1);
this.nativeStorage.getItem(username).then((user)=>{
user.favorites=this.favorites;
this.nativeStorage.setItem(user.username,user).then(()=>{
console.log("deleted favorite")
},error=>{console.error("error en set item")})
})
})
示例4: if
this.serverSecretSubmit().then((res:any)=>{
console.log("secretSubmit "+JSON.stringify(res));
if(res.result=="success"){
if(this.id.startsWith("facebook_")){
var encrypted:string=this.storageProvider.encryptValue('id','facebook');
this.nativeStorage.setItem('id',encodeURI(encrypted));
}else if(this.id.startsWith("kakao_")){
var encrypted:string=this.storageProvider.encryptValue('id','kakao');
this.nativeStorage.setItem('id',encodeURI(encrypted));
}
this.shoplistHandler(res.shopUserInfo);
}else if(res.result=='invalidId'){
console.log("You have no right to access this app");
//this.storageProvider.errorReasonSet('접근권한이 없습니다.');
this.navController.setRoot(ErrorPage);
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('서버로 부터 알수 없는 응답을 받았습니다.');
this.navController.setRoot(ErrorPage);
}
},(err)=>{
示例5: Promise
return new Promise((resolve,reject)=>{
console.log("[loginAgain] id:"+this.storageProvider.id);
if(this.storageProvider.id=="facebook"){
this.fbProvider.login().then((res:any)=>{
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
}else if(this.storageProvider.id=="kakao"){ //kakao login
console.log("kakao login is not implemented yet");
this.kakaoProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
//save shoplist
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
}else{ // email login
this.nativeStorage.getItem("password").then((value:string)=>{
var password=this.storageProvider.decryptValue("password",decodeURI(value));
this.emailProvider.EmailServerLogin(this.storageProvider.id,password).then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(parseFloat(res.version)>parseFloat(this.storageProvider.version)){
console.log("post invalid version");
this.storageProvider.tabMessageEmitter.emit("invalidVersion");
}
resolve();
}else
reject("HttpFailure");
},login_err =>{
reject("NetworkFailure");
});
});
}
});
示例6: tryLogin
tryLogin(event){
if(this.storageProvider.id==undefined){
this.nativeStorage.getItem("id").then((value:string)=>{
console.log("value:"+value);
if(value==null){
console.log("id doesn't exist");
this.app.getRootNav().setRoot(LoginPage);
return;
}else{
var id=this.storageProvider.decryptValue("id",decodeURI(value));
console.log("id:"+id);
this.loginWithExistingId();
}
});
}else{
this.loginWithExistingId();
}
}
示例7: loginWithExistingId
loginWithExistingId(){
var id=this.storageProvider.id;
if(id=="facebook"){
this.fbProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
//save shoplist
console.log("res.email:"+res.email +"res.name:"+res.name);
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=false;
this.storageProvider.userInfoSetFromServer(res.userInfo);
console.log("shoplist...:"+JSON.stringify(this.storageProvider.shoplist));
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure' && res.result=='invalidId'){
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:"facebook"});
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
this.app.getRootNav().setRoot(ErrorPage);
}
},login_err =>{
console.log("move into ErrorPage-"+JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
}else if(id=="kakao"){ //kakao login
//console.log("kakao login is not implemented yet");
// read kakao id and try server login
this.kakaoProvider.login().then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
//save shoplist
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=false;
this.storageProvider.userInfoSetFromServer(res.userInfo);
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure' && res.result=='invalidId'){
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:"kakao"});
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
}
},login_err =>{
console.log(JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
}else{ // email login
this.nativeStorage.getItem("password").then((value:string)=>{
var password=this.storageProvider.decryptValue("password",decodeURI(value));
this.emailProvider.EmailServerLogin(id,password).then((res:any)=>{
console.log("MyApp:"+JSON.stringify(res));
if(res.result=="success"){
if(res.userInfo.hasOwnProperty("shopList")){
//save shoplist
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
this.storageProvider.emailLogin=true;
this.storageProvider.userInfoSetFromServer(res.userInfo);
this.app.getRootNav().setRoot(TabsPage);
}else if(res.result=='failure'&& res.error=='multiLogin'){
// How to show user a message here? move into error page?
// Is it possible to show alert here?
this.app.getRootNav().setRoot(MultiloginPage,{id:id});
}else{
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
}
},login_err =>{
console.log(JSON.stringify(login_err));
//this.storageProvider.errorReasonSet('로그인 에러가 발생했습니다');
//this.app.getRootNav().setRoot(ErrorPage);
});
},(error)=>{
console.log("사용자 정보에 문제가 발생했습니다. 로그인 페이지로 이동합니다.");
this.app.getRootNav().setRoot(LoginPage);
});
}
}
示例8:
tokenGetter: (() => nativeStorage.getItem('id_token'))