菜鸟教程小白 发表于 2022-12-11 18:07:02

android - React Native 应用内浏览器应用


                                            <p><p>我是 React Native 的新手,我需要您的建议。我正在构建一个 React Native 应用内浏览器应用程序来限制浏览器访问页面,除非他们被授予访问权限。我有使用 React Native 提供的 <strong>Linking</strong> 和 <strong>Webview</strong> 的计划。另外,我想以一种用户无法在没有密码的情况下关闭应用程序的方式来实现它。谢谢。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>对于 iOS,您有 <a href="http://facebook.github.io/react-native/releases/0.38/docs/webview.html#onshouldstartloadwithrequest" rel="noreferrer noopener nofollow"><code>onShouldStartLoadWithRequest</code></a>方法,它可以让你决定哪些请求应该被允许,哪些不应该。已尝试将此功能移植到 Android <a href="https://github.com/facebook/react-native/pull/6478" rel="noreferrer noopener nofollow">PR</a> ,但似乎不太可能很快发布版本。然而,这里有两个解决方案: 在 <code>state</code> 中设置当前 URL。然后订阅<a href="http://facebook.github.io/react-native/releases/0.38/docs/webview.html#onloadstart" rel="noreferrer noopener nofollow"><code>onLoadStart</code></a>方法并在那里检查新的 URL。如果确实满足了你的需求,把它设置为<code>state</code>,有效的继续渲染(一不小心你可能会陷入死循环,可能URL和state里的一样, 没做什么)。否则,用旧 URL 替换新 URL,或调用 <code>goBack()</code>。第二种选择是实现一个自定义 WebView,它扩展了 React Native 的一个并实现了这个功能。见 <a href="https://stackoverflow.com/a/10121273/2628463" rel="noreferrer noopener nofollow">this answer</a>供引用,<a href="https://github.com/lucasferreira/react-native-webview-android" rel="noreferrer noopener nofollow">this component</a>查看自定义 WebView 的实现引用。</p></p>
                                   
                                                <p style="font-size: 20px;">关于android - React Native 应用内浏览器应用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40746842/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40746842/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: android - React Native 应用内浏览器应用