如何在Flutter中实现深层链接,并重定向到应用商店? [英] How to implement deep linking in flutter, with redirect to app store?

查看:843
本文介绍了如何在Flutter中实现深层链接,并重定向到应用商店?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以实现抖动中的深层链接,因此,如果用户单击链接,则将他们重定向到应用程序的特定部分(假定已安装该应用程序,但如果没有),重定向到相应的应用程序商店,以安装应用程序,然后带到该特定部分。

Is there a way to achieve deep linking in flutter, so that if a user click on a link then they are redirected to a specific part of the app, given that the app in installed, but if it isn't, they are redirected to the respective app store, to install the application and then taken to that specific part.

在寻找解决方案时,我遇到了一个名为<$ c $的软件包c> uni_links ,但我不确定它是否可以满足此要求。

While searching for a solution I came across this package called uni_links but I am not sure if it can fulfil this requirement.

推荐答案

您可以使用为此目的Firebase动态链接:

You can use Firebase dynamic links for this purpose:

https ://firebase.google.com/docs/dynamic-links

上面写着:

如果用户在iOS或Android上打开动态链接并且未安装
您的应用,则系统会提示用户安装该应用;然后,安装后
,您的应用程序将启动并可以访问链接。

if a user opens a Dynamic Link on iOS or Android and doesn't have your app installed, the user can be prompted to install it; then, after installation, your app starts and can access the link.

您可以找到有关如何实现此操作的信息和Flutter一起在这里:

You can find information on how to implement this with Flutter here:

https://pub.dev/ package / firebase_dynamic_links

我已经在Android和iOS上尝试过了,效果很好。如果未安装该应用程序,则将打开Goog​​le Play商店或Apple AppStore。用户可以点击安装,然后点击打开。之后,启动您的应用程序,并将动态链接发送到您的应用程序(通过剪贴板通过iOS在iOS上),您可以在其中访问该应用程序,如上面的网站所述。即在第一个initState方法启动应用后,您可以调用

I have tried it myself with Android and iOS and it worked fine. If the app is not installed, the Google Play store or Apple AppStore is opened. The user can tap "Install" and then "Open". Afterward your app is started and the dynamic link is sent to your app (on iOS via the clipboard) where you can access it as explained on the website above. I.e. right after the start of your app in the first initState method you can call

final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.retrieveDynamicLink();
final Uri deepLink = data?.link;

获取深层链接。但是,以我在iOS上的经验来看,现在检索链接还为时过早。尝试时出现 null。似乎要花一点时间。然后,我使用了WidgetsBindingObserver,并在didChangeAppLifecycleState方法中查看了 AppLifecycleState.resumed 。我在那里叫retrieveDynamicLink。由于权限请求(如果用户允许通知),该方法被调用了两次。第一次返回null,但是第二次返回深度链接。因此,我的解决方案如下所示:

to get the deep link. However in my experience on iOS this is too early to retrieve the link. I got "null" when trying it. It seemed to take a moment. I then used a WidgetsBindingObserver and watched in the didChangeAppLifecycleState method for AppLifecycleState.resumed. There I called retrieveDynamicLink. Due to a permission request (if the user allows notifications) the method was called twice. The first time it returned null but when it was called the second time it returned the deep link. So my solution looks like this:

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      _retrieveDynamicLink();
    }
  }

  /**
   * Laden des Deep Link nach der Installation.
   */
  Future<void> _retrieveDynamicLink() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.retrieveDynamicLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
        // Use the deepLink
        // ...
    }
}

这篇关于如何在Flutter中实现深层链接,并重定向到应用商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆