例如,我在我的Flutter应用程序中有一个情况,当用户可以恢复他的密码。
在这种情况下,用户将收到一封电子邮件链接,我希望通过点击该链接,我的Flutter应用程序将打开并路由到特定的屏幕。
你需要从这个角度来看待它: 如何通过URL打开我的iOS/Android应用程序, 即 应用程序深层链接。
它们各自有自己的实现:
或者您可以选择更全面的SDK,能够为您两者都实现:
有一个非常好的插件可供使用,
https://github.com/avioli/uni_links
它还详细解释了您需要如何配置iOS和Android使其正常工作(我认为这是最困难的部分); 另一个很好的信息来源是这篇博客文章
因此,你必须使用 动态链接
。
最好的解决方案是使用Firebase动态链接。
Firebase动态链接的优势之一:将移动网站用户转换为原生应用用户。
使用动态链接,您可以将用户从您的移动网站无缝地转换到应用程序中相应的内容。而且,由于这些链接在应用安装过程中保留,即使是新用户也可以在您的移动网站上继续上次未完成的操作,没有任何影响。
如果您不想从链接中获取数据,那么您无需使用任何包来启动应用程序。
<!-- App Link sample -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="myapp.flutter.com" android:pathPrefix="/success" />
<data android:scheme="https" android:host="myapp.flutter.com" android:pathPrefix="/failure" />
</intent-filter>
<!-- Deep Link sample -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Add optional android:host to distinguish your app
from others in case of conflicting scheme name -->
<data android:scheme="app" android:host="success" />
<data android:scheme="app" android:host="failure" />
<!-- <data android:scheme="sample" /> -->
</intent-filter>