react-native - React Native webview with login facebook总是在发布模式下重定向到另一个url(仅限android)
问题描述
我有一个带有这些代码行的 webview:
<WebView
userAgent={`Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM1.180201.021; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36`}
source={{
uri: `https://www.facebook.com/v8.0/dialog/oauth?client_id=xxx&redirect_uri=yyyy`,
}}
incognito={true}
onNavigationStateChange={(state) => {
let url = state.url;
console.log(url);
var regex = /[?&]([^=#]+)=([^&#]*)/g,
params = {},
match;
while ((match = regex.exec(url))) {
params[match[1]] = match[2];
}
if (params.code) {
setLoading(true);
setModalVisible(false);
processFbcode(params.code);
}
if (params.error) {
setLoading(false);
setModalVisible(false);
}
}}
startInLoadingState={true}
renderLoading={() => (
<ActivityIndicator
style={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0,0,0,0.2)',
}}
size="large"
color="#0000ff"
/>
)}
style={{marginBottom: '10%'}}
/>
在调试模式下,我运行该代码没有任何错误,控制台日志显示:
about:blank
=> https://www.facebook.com/v8.0/dialog/oauth?client_id=xxx&redirect_uri=yyyy
=> 其他用于身份验证的 url
但是在发布模式下,使用上面相同的代码和 webview 中的相同 url (source={{...}}),我看到adb logcat
:
https://m.facebook.com/login.php?skip_api_login=1&api_key=xxx&kid_directed_site=0&app_id=zzz&signed_next=1&next=(myUrlAbove)&cancel_url=(otherURL)%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&display=touch&locale=vi_VN&pl_dbl=0&refsrc=https%3A%2F%2Fm.facebook.com%2Fv8.0%2Fdialog%2Foauth&_rdr
为什么以 2 模式反应原生 webview 加载 2 个不同的 url?(在 webview 源代码中提供相同的处理代码和相同的 init url)?
P/s:在调用之前,我已经在我的 facebook 开发者应用程序上定义了密钥哈希react-native run-android --variant=release
我的本机版本:0.63.4
我的 react-native-webview 版本:11.3.1(最新)
提前致谢!
解决方案
推荐阅读
- c# - 如果班级发生变化,如何强制其他地方发生变化?
- javascript - 延迟后的承诺
- php - 使用 ajax 从 mysql DB 检索和打印数据到文本框(如何在同一个 php 页面中使用它两次)
- r - 处理发生在同一日期的值
- mongodb - 去不正确地解释 http 请求
- javascript - 正则表达式中的插值
- reactjs - 主题状态更改将在 ThemeProvider 中仅重新呈现一次
- laravel - 在没有 Pusher 和 Redis 的情况下使用 Laravel 事件?
- multidimensional-array - SystemVerilog中二维切片
- css - Material UI 和 ReactJS,如何使用 withStyles 为选定的 ListItem 设置样式?