【问题标题】:How to pass oAuth session token to react-native webview from salesforce react native app?如何将 oAuth 会话令牌从 salesforce react native 应用程序传递给 react-native webview?
【发布时间】:2019-05-23 09:07:30
【问题描述】:

我们正计划开发一个自定义的 react-native 移动应用,我们需要通过 Lightningout.js 在移动 webview 中显示闪电应用页面。

我们使用 forcereact (Salesforce mobile sdk) 创建了一个 react-native 应用程序,我们可以成功登录并获取 OAuth 令牌。我们要求通过闪电输出在 react-native webview 中显示闪电组件页面。为此,我们应该将 oAuth 令牌安全地传递给 webview。有没有办法将令牌传递给 react-native webview?

【问题讨论】:

    标签: react-native salesforce salesforce-mobile-sdk


    【解决方案1】:

    不是很清楚你的问题。但是如果你想在 html 页面和 react-native 之间进行交互。你可以使用 postMessage 和 onMessage。

    export default class Test extends React.Component{
        constructor(props){
            super(props);
        }
    
        handleMessage(msg){
    
        }
    
        postMessage(msg){
            this.webview.postMessage(msg)
        }
    
        render(){
            return (
                <Webview 
                    source={{uri:"http://test.com"}}
                    onMessage={this.handleMessage}
                    ref={ref => { this.webview = ref }}
                />
            )
        }
    
    }
    

    【讨论】:

    • 我正在从项目目录加载 index.html 文件。在加载时,我应该从 react-native 获取数据。this.webview.postMessage(msg) 可以将数据传递到 html 页面吗?
    • @Senthilkumar.S 是的。在您的 index.html 文件中,使用 window.onload = function() { document.addEventListener('message', function(msg) { window.alert(msg.data); });
    猜你喜欢
    • 2020-02-20
    • 2020-04-02
    • 1970-01-01
    • 2022-11-10
    • 2019-09-07
    • 2021-03-17
    • 2018-01-20
    • 2016-05-11
    • 1970-01-01
    相关资源
    最近更新 更多