简体   繁体   English

Flutter Firebase 动态链接不适用于 facebook

[英]Flutter Firebase Dynamic Links Not working on facebook

I'm using dynamic links for creating links and share it from my app to social media platforms, I tried to share on WhatsApp and messager and it's working great no problems.我正在使用动态链接来创建链接并将其从我的应用程序共享到社交媒体平台,我尝试在 WhatsApp 和 messager 上共享并且它运行良好没有问题。

The only exception when trying to open a link from Facebook, it opens the InAppBrowser first then opening the play store instead of my app!!!尝试打开来自 Facebook 的链接时唯一的例外是,它首先打开 InAppBrowser,然后打开 Play 商店而不是我的应用程序!!!

If there any tweaks or workarounds for this issue please share it here as all the app marketing campings will depend on Facebook.如果此问题有任何调整或解决方法,请在此处分享,因为所有应用营销露营都将取决于 Facebook。

I don't know what code to put it here as Facebook is the only exception here!我不知道把什么代码放在这里因为 Facebook 是这里唯一的例外!

Anyway, here's the code for sharing and initiate:无论如何,这是共享和启动的代码:

class ShareBloc extends Bloc<ShareEvent, ShareState> {

  final GlobalKey<NavigatorState> navigateKey;

  ShareBloc(this.navigateKey): assert(navigateKey != null);

  @override
  ShareState get initialState => ShareInitial();

  @override
  Stream<ShareState> mapEventToState(
    ShareEvent event,
  ) async* {

    if ( event is OnDynamicLinkInitial ) {


      final PendingDynamicLinkData pendingDynamicLinkData = await FirebaseDynamicLinks.instance.getInitialLink();
      final Uri deepLink = pendingDynamicLinkData?.link;

      if ( deepLink != null ) {
        print(deepLink.path);
        navigateKey.currentState.pushNamed(SearchPage.routeName);
      }

      FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData pendingDynamicLinkData) async {
          final Uri deepLink = pendingDynamicLinkData?.link;

          if (deepLink != null) {
            print(deepLink.path);
            navigateKey.currentState.pushNamed(SearchPage.routeName);
          }
        },
        onError: (OnLinkErrorException error) async {
          print("ERR DeepLink: $error");
        }
      );
    }


    if ( event is ShareOnSocial ) {
      try {
        yield ShareLoading();
        final DynamicLinkParameters dynamicLinkParameters = DynamicLinkParameters(
          uriPrefix: 'http://xxx.page.link', 
          link: Uri.parse('https://xxx.xxx.com/xxx/xxx/${event.post.id}'),
          androidParameters: AndroidParameters(
            packageName: 'com.xxx.xxx',
            minimumVersion: 17,
          ),
          dynamicLinkParametersOptions: DynamicLinkParametersOptions(
            shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
          ),
          socialMetaTagParameters: SocialMetaTagParameters(
            title: event.post.title,
            // description: event.post.excerpt,
            imageUrl: Uri.parse(event.post.image)
          ),
          navigationInfoParameters: NavigationInfoParameters(
            forcedRedirectEnabled: true
          )
        );

        final shortDynamicLink = await dynamicLinkParameters.buildShortLink();
        final Uri shortUrl = shortDynamicLink.shortUrl;

        await Share.share(
          "${event.post.title} $shortUrl",
          subject: event.post.title,
        );

        yield ShareSuccess();
      } catch (e) {
        yield ShareFailure();
      }
    }
  }
}

I got few resources我得到的资源很少

Resources:资源:

https://medium.com/dev-genius/firebase-flutter-dynamic-links-step-by-step-guide-630402ee729b https://medium.com/dev-genius/firebase-flutter-dynamic-links-step-by-step-guide-630402ee729b

https://pub.dev/packages/firebase_dynamic_links https://pub.dev/packages/firebase_dynamic_links

Firebase Setup: Setup app.domain.com in the firebase dynamic link section with TXT DNS change provided. Firebase 设置:在 firebase 动态链接部分设置app.domain.com ,提供 TXT DNS 更改。

Use dynamically generated links from flutter code itself so no need to add any links in the firebase dashboard.使用 flutter 代码本身动态生成的链接,因此无需在 firebase 仪表板中添加任何链接。

Code代码

Make sure to use the latest packages:确保使用最新的软件包:

Pubspec.yaml发布规范 yaml

firebase_core: ^0.7.0
firebase_auth: ^0.20.0+1
firebase_dynamic_links: ^0.7.0+1

Info.plist信息列表

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
    <string>https://app.yourdomain.com</string>
</array>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM