gpt4 book ai didi

react-native - react-native (expo) 中的 AuthSession 不会返回到应用程序 Android

转载 作者:行者123 更新时间:2023-12-04 03:57:13 24 4
gpt4 key购买 nike

我有一个用 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 和 app hide webapp modal 并显示我需要的内容。

但是,当我将应用程序导出到 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://')用作我定义的模式,但也没有成功。

最佳答案

schemeapp.json一定是你的 android.package姓名。

所以在你的情况下 scheme: "com.roche.mynewapp"
这对我有用。更多详情请关注 世博文档 https://docs.expo.io/versions/latest/sdk/app-auth/#appauthoauthredirect

关于react-native - react-native (expo) 中的 AuthSession 不会返回到应用程序 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54366634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com