利用自定义分享方案,从 Firebase 邀请迁移到 Dynamic Links
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Firebase Invites 既提供了一种在您的应用中接收 Firebase Dynamic Links 的机制,又提供了一种通过短信或电子邮件分享该链接的功能。我们开发 Firebase Invites 的目的是帮助开发者通过口口相传来扩大其应用的用户群,但随着时间的推移,我们发现开发者找到了鼓励用户与其朋友分享自己最喜爱应用的更好方式,而不仅仅是 Firebase Invites 现在所具有的功能。
我们还发现,虽然 Firebase Invites 的使用减少了,但许多人仍将 Firebase Dynamic Links 作为用户间分享解决方案的关键组成部分。因此,我们正在集中精力、加大力度,使 Firebase Dynamic Links 成为在您的应用中构建用户间分享功能的理想方式。作为此次转变的一部分,我们已弃用 Firebase Invites 功能,并将从 2020 年 1 月 24 日起停止支持该功能。
这意味着什么?对我有何影响?
自 2020 年 1 月 24 日起,您的用户已无法再发送或接收 Firebase Invites,而且 Firebase 邀请后端服务会在您进行发送和接收邀请链接的调用时开始返回错误响应。当前 SDK 包含错误处理功能,有助于确保这些服务器响应的正常失败情况,因此您的用户将能够继续使用您的应用而不会发生崩溃,但我们建议您不再使用 Firebase Invites,而是改用 Firebase Dynamic Links 和自定义分享解决方案。
下面介绍如何实现这一目标!
使用 Firebase Dynamic Links 创建邀请链接
首先,创建 Dynamic Link,让用户可以与其朋友分享。庆幸的是,您可能已经熟悉此步骤,因为它与您设置 Firebase Invites 的方式类似。不过,如果您的用户通过社交网络分享您的应用,那么您还可以向动态链接添加特定参数(例如,向您的链接添加社交元数据),以自定义所分享网址的显示效果。
构建分享解决方案
接下来,您就可以为用户构建分享解决方案,使用户能够与其朋友分享该链接。您希望在这一步构建什么样的分享解决方案,取决于您要以怎样的方式提供分享功能(用于取代 Firebase Invites 中的原有功能);但对于大多数移动应用,您可以利用平台中内置的功能。
对于 Android,有一种简单的解决方案可同时囊括短信、电子邮件以及其他常用的社交网络和聊天应用等分享途径,那就是使用一个通用 intent,并将其操作设置为 Intent.ACTION_SEND
。这样就可以方便地将您应用中的数据分享给用户所安装的可以处理分享 intent 的任何应用。
与下例类似的代码可以用于这个场景(建议您在自己的代码中使用常量字符串资源):
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Here's a new lesson for" +
" learning more Miwok vocabulary:\n\n" + dynamicLink);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Let's Learn Miwok!");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent,
getResources().getText(R.string.send_to)));
如需更全面的示例并了解详情,请查看此将简单数据发送到其他应用指南。
上面的代码段会引发如下面屏幕中所示的邀请流程:

如果是 iOS 开发者,您可以使用 UIActivityViewController
,将作为数据一部分创建的链接传递给自定义 VC。此方法将引发类似于以下屏幕的分享流程:

在应用中接收 Dynamic Link
要在 Firebase 邀请功能停用后在您的应用中提供用户间分享功能,最后一步是在您的应用中接收 Dynamic Link。
对于 Android,此过程保持不变,因此您在这一步无需进行大的更改。唯一的区别是,如果不使用 Firebase Invites,将不再有邀请 ID,因此如果您的应用目前通过调用 FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(data)
来提取邀请 ID,您需要移除该调用。如需详细了解这一点,请参阅在 Android 应用中接收 Dynamic Links 指南。
对于 iOS,您需要从 FIRReceivedInvite 对象更改为 FIRDynamicLink 对象,这两个对象包含类似的数据。如需了解详情,请参阅在 iOS 应用中接收 Dynamic Links 指南。
Unity 开发者可以使用如上所述的许多开源库和等效解决方案来迁移用户间分享功能。如果在提供合适的解决方案方面需要帮助,请访问下方链接的支持资源。
Firebase Invites 一直是我们引以为傲的优秀工具。
展望未来,我们将加倍努力使 Firebase Dynamic Links 变得更好,这样您就可以更加灵活、有效地鼓励用户邀请其他人使用您的应用。如果您对设置 Firebase Dynamic Links 和自定义分享解决方案有任何疑问,请访问 StackOverflow 或我们的任何其他支持论坛。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["\u003cbr /\u003e\n\n| Firebase Invites is deprecated. On **January 24th, 2020** , we will discontinue support for Firebase Invites. You will be able to use [Firebase Dynamic Links](/docs/dynamic-links) with a custom sharing solution.\n\nFirebase Invites provided both a mechanism for receiving\n[Firebase Dynamic Links](/docs/dynamic-links) in your app, as well as a\nfeature to share that link via SMS or email. We developed\nFirebase Invites to help you grow your app users through word of mouth,\nbut over time, we learned that you found better ways to encourage users to share\ntheir favorite apps with their friends, beyond what Firebase Invites does\ntoday.\n\nWe also saw that while usage of Firebase Invites dropped, many of you\nwere still using Firebase Dynamic Links as the key ingredient of your user-to-user\nsharing solution. So, we're strengthening our focus and increasing our effort to\nmake Firebase Dynamic Links the best way to build user-to-user sharing capabilities\ninto your app. As part of this shift, we have deprecated the\nFirebase Invites feature, and will discontinue support starting on\n**January 24th, 2020**.\n\nWhat does this mean and how does it impact me?\n\nStarting on January 24th, 2020, your users will no longer be able to send\nor receive Firebase Invites, and the invites backend service will start\nreturning error responses when making calls to send and receive an invite link.\nThe current SDKs include error handling to help ensure graceful failure cases\nfor these server responses, so your users will be able to continue using your\napp without crashing, but we recommend that you no longer use\nFirebase Invites, and switch to an alternative solution using\nFirebase Dynamic Links with a custom sharing solution.\n\nHere is how to do that!\n\nCreate invitation links with Firebase Dynamic Links\n\nFirst, [Create a Dynamic Link](/docs/dynamic-links/create-links) that your\nusers can share with their friends. The good news is that you're likely familiar\nwith this step already because it's similar to how you set up Firebase Invites.\nBut you can also add specific parameters to your Dynamic Link, such as\n[adding social metadata to your links](/docs/dynamic-links/link-previews) if\nyour users share your app via a social network to customize the appearance of\nthe URL that gets shared.\n\nBuild a sharing solution\n\nNext, build your sharing solution for your users to be able to share that link\nwith their friends. What you will want to build here will vary depending on how\nyou want to provide the sharing feature that will replace the previous one in\nFirebase Invites, but for most mobile apps you can take advantage of\nfeatures already built into the platform.\n\nFor Android, one simple solution that covers both SMS and email sharing, as well\nas other popular social network and messaging apps, is to use a generic intent\nwith an action set as `Intent.ACTION_SEND`. This\nprovides a convenient way to share data from your app to any app the user has\ninstalled that can handle a share intent.\n\nSomething similar to the following example should work here (recommending that\nyou use constant string resources in your own code): \n\n```css+lasso\nIntent sendIntent = new Intent();\nsendIntent.setAction(Intent.ACTION_SEND);\nsendIntent.putExtra(Intent.EXTRA_TEXT, \"Here's a new lesson for\" +\n \" learning more Miwok vocabulary:\\n\\n\" + dynamicLink);\nsendIntent.putExtra(Intent.EXTRA_SUBJECT, \"Let's Learn Miwok!\");\nsendIntent.setType(\"text/plain\");\nstartActivity(Intent.createChooser(sendIntent,\n getResources().getText(R.string.send_to)));\n```\n\nFor a fuller example and more details, check out this guide for [sending simple\ndata to other apps](https://developer.android.com/training/sharing/send).\n\nThe code snippet above will generate something like invitation flow shown in the\nscreens below:\n\nFor iOS developers, you can use a\n`UIActivityViewController`, passing in the link\ncreated as part of the data to the custom VC. This method would provide a\nsharing flow similar to the screens below:\n\nReceive a Dynamic Link in your app\n\nFinally, the last step to provide user-to-user sharing for your app after the\nsunset is in receiving a Dynamic Link in your app.\n\nFor Android, this process remains the same so you won't need to change much\nhere. The only difference is that without Firebase Invites, there will no\nlonger be an invitation ID, and so you would need to remove the call to extract\nthe invite ID via `FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(data)`,\nif your app is making that call. For more details on this piece, please see the\nguide on [Receiving Dynamic Links in your Android app](/docs/dynamic-links/android/receive).\n\nFor iOS, this would require changing from the [FIRReceivedInvite](/docs/reference/ios/firebaseinvites/api/reference/Classes/FIRReceivedInvite)\nobject to the [FIRDynamicLink](/docs/reference/ios/firebasedynamiclinks/api/reference/Classes/FIRDynamicLink)\nobject, which both contain similar data. Please see the guide on\n[Receiving Dynamic Links in your iOS app](/docs/dynamic-links/ios/receive) for\nmore details.\n\nFor Unity developers, there are a number of open-source libraries and equivalent\nsolutions as those described above to migrate your user-to-user sharing\nfunctionality. If you need any assistance on providing a suitable solution,\nplease reach out to the support resources linked further below.\n\nFirebase Invites has been a great tool that we're proud to have built.\nAs we look towards the future, we're excited to double down on making\nFirebase Dynamic Links even better so you have more flexibility and control over how\nyou encourage users to invite others to your app. If you have any questions\nabout setting up your Firebase Dynamic Links and custom sharing solutions, please\nreach out on [StackOverflow](https://stackoverflow.com/questions/tagged/firebase-dynamic-links), or any of\nour [additional support forums](https://firebase.google.com/support/)."]]