如何获取 Expo 静态深度链接进行开发?

Posted

技术标签:

【中文标题】如何获取 Expo 静态深度链接进行开发?【英文标题】:How to get Expo static deep link for development? 【发布时间】:2020-02-13 16:14:33 【问题描述】:

我需要一个用于开发的 Expo 静态深层链接,用于与第三方 (Cognito) 进行 Oauth 重定向

我使用了Linking.makeUrl(),但这会返回一个带有动态本地 IP 地址的深层链接 exp://10.0.0.107:19000 这对于团队中的其他开发人员来说是不一致的。

文档位于: https://docs.expo.io/versions/latest/workflow/linking/#linking-module

说各种环境链接的样子

在 Expo 客户端中发布的应用程序exp://exp.host/@community/with-webbrowser-redirect

独立发布的应用程序myapp://

开发exp://wg-qka.community.app.exp.direct:80

我已尝试过开发链接,但无法打开。

【问题讨论】:

看aws-amplify.github.io/docs/js/… 嗯所以也许exp://127.0.0.1:19000@oleg 【参考方案1】:

我也有类似的问题,这是我的解决方案 也发到https://github.com/aws-amplify/amplify-js/issues/4244#issuecomment-586845322

如果有人仍然需要 expo+amplify+social 登录方面的帮助

应用程序.json

  "expo": 
    "scheme": "exposchemeappname://"  // use any name you like, just make it unique
  

应用程序.js
import  Linking  from 'expo';
import * as WebBrowser from 'expo-web-browser';

import awsconfig from './aws-exports';

const amplifyConfig = 
  ...awsconfig,
  oauth: 
    ...awsconfig.oauth,
    urlOpener: async (url, redirectUrl) => 
      // On Expo, use WebBrowser.openAuthSessionAsync to open the Hosted UI pages.
      const  type, url: newUrl  = await WebBrowser.openAuthSessionAsync(url, redirectUrl);

      if (type === 'success') 
        await WebBrowser.dismissBrowser();

        if (Platform.OS === 'ios') 
          return Linking.openURL(newUrl);
        
      
    ,
    options: 
      // Indicates if the data collection is enabled to support Cognito advanced security features. By default, this flag is set to true.
      AdvancedSecurityDataCollectionFlag: true
    ,
  
;

const expoScheme = "exposchemeappname://"
// Technically you need to pass the correct redirectUrl to the web browser.
let redirectUrl = Linking.makeUrl();
if (redirectUrl.startsWith('exp://1')) 
  // handle simulator(localhost) and device(Lan)
  redirectUrl = redirectUrl + '/--/';
 else
if (redirectUrl === expoScheme) 
  // dont do anything
 else 
  // handle the expo client
  redirectUrl = redirectUrl + '/'

amplifyConfig.oauth.redirectSignIn = redirectUrl;
amplifyConfig.oauth.redirectSignOut = redirectUrl;

Amplify.configure(amplifyConfig);

确保添加以下重定向 URL 以放大 amplify auth update

# development
exp://127.0.0.1:19000/--/
exp://192.168.1.101:19000/ # depends on your lan ip

# expo client
exp://exp.host/@[EXPO_ACCOUNT]/[EXPO_APPNAME]/

# expo scheme for standalone
exposchemeappname://

【讨论】:

【参考方案2】:

你可以使用Linking模块

通过运行安装它:expo install expo-linking

将其导入文件顶部:import * as Linking from "expo-linking";

然后使用:Linking.makeUrl(); 获取指向您由 expo 客户端托管的应用程序的链接

console看网址

【讨论】:

以上是关于如何获取 Expo 静态深度链接进行开发?的主要内容,如果未能解决你的问题,请参考以下文章