【发布时间】:2019-01-25 13:50:07
【问题描述】:
我有一个用 React Native 代码编写的应用程序。我有这个功能的组件:
handleLogin = async () => {
let redirectUrl = AuthSession.getRedirectUrl();
let results = await AuthSession.startAsync({
authUrl: `https://exampleurl.com/?uid=${CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUrl)}`
});
if (results.type !== 'success') {
this.setState({ didError: true });
} else {
if(results.params.token != undefined) {
let user = {
name: results.params.uname,
surname: results.params.surname,
token: results.params.token
}
this.setState({ userInfo: user});
this.props.loginUser(this.state.userInfo);
}
}
};
问题是,当我在 Expo 中运行它们时,它运行良好,打开适当的 URL,我登录,然后服务器成功返回到 redirect_uri 和应用程序隐藏 webapp 模式并显示我需要的内容。
但是当我将应用程序导出到 android 并在我的手机中安装这个 apk 时,它仍然可以正常工作,点击打开 webview,我以用户身份登录并返回。但它停留在“返回应用程序”步骤。它永远不会返回应用程序。我还在 app.json 中定义了架构:
{
"expo": {
"name": "MyNewApp",
"slug": "MyNewApp",
"privacy": "public",
"sdkVersion": "32.0.0",
"platforms": [
"ios",
"android"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"scheme": "MyNewApp",
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"bundleIdentifier": "com.roche.mynewapp",
"supportsTablet": true
},
"android": {
"package": "com.roche.mynewapp"
}
}
}
我做错了什么?我尝试将重定向 uri 设置为 encodeURIComponent('MyNewApp://') 以用作我定义的架构,但也没有成功。
【问题讨论】:
-
任何解决方案??
-
我删除了 expo 并切换到默认的 React 东西 :)
-
即使我最后也喜欢那个:P
标签: react-native expo