本地存储API在NativeScript WebView中不起作用 [英] Local Storage APIs do not work within NativeScript WebView

查看:61
本文介绍了本地存储API在NativeScript WebView中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是一个托管在{N} WebView中的Web应用程序.用户名&密码存储在localStore中.当我离开应用程序并重新输入时,我没有数据,我必须返回登录.

My application is a web app hosted within a {N} WebView. The username & password are store in the localStore. When I leave the app and re-enter I do not have data and I have to go back to login.

有人可以帮我吗?或说明如何在应用程序中调试Web视图. 该网页是使用Angular 4开发的,而应用是使用NativeScript开发的.

Could someone help me? or explain how to debug a web view in an app. the webpage is developed with Angular 4 and the app with NativeScript.

推荐答案

在Android中,localStorage API除非启用它们,否则将不起作用.您可以通过在加载事件时访问本机WebView的设置来启用它.

With Android localStorage APIs won't work until you enable them. You could enable it by accessing the native WebView's settings upon loaded event.

export function onWebViewLoaded(args) {
    const webView = args.object;
    if (webView.android) {
        webView.android.getSettings().setDomStorageEnabled(true);
        webView.android.getSettings().setDatabaseEnabled(true);
    }
}

游乐场样品

在这之间,是否可以使用localStorage保存用户名/密码等机密信息是一个不同的问题.我的回答是否",因为它很容易/易于使用,所以您不能使用它.通常,您应该使用用户提供的这些凭据来访问登录api,您应该会获得access token,该名称随后将用于与服务器的任何通信.您可以将此令牌存储在localStoage中,注销后将其清除.

Between, whether you can localStorage for saving confidential informations such as username / password is a different question here. My answer will be no, you can't use it as it's easy / open to access. Generally you should hit the login api with these credentials given by user, you should probably get access token which you will use for any communication with server subsequently. You could store this token in your localStoage, clear it upon logout.

这篇关于本地存储API在NativeScript WebView中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆