پیوندهای دینامیک Firebase را در یک برنامه Flutter دریافت کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای دریافت پیوندهای دینامیک Firebase که ایجاد کردهاید ، باید SDK پیوندهای پویا را در برنامه خود قرار دهید و هنگام بارگیری برنامه شما، متد FirebaseDynamicLinks.getDynamicLink() را فراخوانی کنید تا دادههای ارسال شده در پیوند پویا دریافت شود.
از دایرکتوری ریشه پروژه Flutter خود، دستور زیر را برای نصب افزونه Dynamic Links اجرا کنید:
flutter pub add firebase_dynamic_links
اگر در حال ساختن یک برنامه اندروید هستید، صفحه تنظیمات پروژه کنسول Firebase را باز کنید و مطمئن شوید که کلید امضای SHA-1 خود را مشخص کرده اید. اگر از App Links استفاده می کنید، کلید SHA-256 خود را نیز مشخص کنید.
ادغام پلتفرم
مراحل ادغام پلتفرم زیر را برای پلتفرم هایی که برنامه خود را برای آنها می سازید، تکمیل کنید.
اندروید
در اندروید، باید یک فیلتر قصد جدید برای پیوندهای عمیق دامنه خود اضافه کنید، زیرا در صورت نصب برنامه، پیوند پویا به دامنه شما هدایت می شود. این برای دریافت دادههای Dynamic Link پس از نصب/بهروزرسانی از Play Store و یک ضربه زدن روی دکمه Continue، لازم است. در AndroidManifest.xml :
وقتی کاربران یک پیوند پویا را با پیوند عمیق به طرح و میزبانی که مشخص کردهاید باز میکنند، برنامه شما فعالیت را با این فیلتر قصد شروع میکند تا پیوند را مدیریت کند.
مرحله بعدی اطمینان از ثبت اثر انگشت SHA-256 گواهی امضا در کنسول Firebase برای برنامه است. میتوانید جزئیات بیشتری درباره نحوه بازیابی اثر انگشت SHA-256 خود را در صفحه تأیید اعتبار مشتری خود بیابید.
در صفحه تنظیمات پروژه کنسول Firebase، مطمئن شوید که برنامه iOS شما با شناسه App Store و Team ID شما به درستی پیکربندی شده است.
در سایت Apple Developer، با فعال بودن قابلیت Associated Domain، یک نمایه تامین کننده برای برنامه خود ایجاد کنید.
در Xcode موارد زیر را انجام دهید:
برنامه خود را در زیر هدر TARGETS باز کنید.
در صفحه Signing & Capabilities، مطمئن شوید که تیم شما ثبت شده است و نمایه تامین شما تنظیم شده است.
در صفحه Signing & Capabilities، Associated Domains را فعال کنید و موارد زیر را به لیست Associated Domains اضافه کنید (مثال را با دامنه خود جایگزین کنید):
applinks:example.page.link
در صفحه اطلاعات، یک نوع URL به پروژه خود اضافه کنید. فیلد URL Schemes را روی شناسه بسته نرم افزاری خود تنظیم کنید. (شناسه می تواند Bundle ID یا هر چیزی که می خواهید باشد.)
اگر یک دامنه سفارشی برای پروژه Firebase خود راه اندازی کرده اید، پیشوند URL Link Dynamic Link را با استفاده از کلید FirebaseDynamicLinksCustomDomains به فایل Info.plist پروژه iOS خود اضافه کنید.
اختیاری: غیرفعال کردن استفاده SDK پیوندهای پویا از مقوای iOS.
به طور پیشفرض، Dynamic Links SDK از مقوا برای بهبود قابلیت اطمینان پیوندهای عمیق پس از نصب استفاده میکند. با استفاده از مقوا، Dynamic Links میتواند مطمئن شود که وقتی کاربر یک پیوند پویا را باز میکند، اما باید ابتدا برنامه شما را نصب کند، کاربر میتواند هنگام باز کردن برنامه برای اولین بار پس از نصب، بلافاصله به محتوای پیوند شده اصلی برود.
نقطه ضعف این کار این است که استفاده از مقوا باعث ایجاد اعلان در iOS 14 به بعد می شود. بنابراین، اولین باری که کاربران برنامه شما را باز میکنند، اگر کارت پستال حاوی URL پیوند پویا باشد، اعلانی مبنی بر دسترسی برنامه شما به کارتبورد مشاهده میکنند که میتواند باعث سردرگمی شود.
برای غیرفعال کردن این رفتار، فایل Info.plist پروژه Xcode خود را ویرایش کنید و کلید FirebaseDeepLinkPasteboardRetrievalEnabled را روی NO تنظیم کنید.
پیوندهای عمیق را مدیریت کنید
برای مدیریت یک پیوند پویا در برنامه خود، دو سناریو نیاز به پیاده سازی دارد.
FirebaseDynamicLinks.onLink - کنترل کننده رویداد که یک Stream حاوی PendingDynamicLinkData?
Android همیشه پیوند را از طریق FirebaseDynamicLinks.getInitialLink از حالت پایان یافته دریافت می کند، اما در iOS، تضمینی نیست. بنابراین، ارزش آن را دارد که هر دو را به ترتیب زیر تنظیم کنید تا مطمئن شوید که برنامه شما پیوند را دریافت می کند:
Future<void>main()async{WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp(options:DefaultFirebaseConfig.platformOptions);// Check if you received the link via `getInitialLink` firstfinalPendingDynamicLinkData?initialLink=awaitFirebaseDynamicLinks.instance.getInitialLink();if(initialLink!=null){finalUrideepLink=initialLink.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}FirebaseDynamicLinks.instance.onLink.listen((pendingDynamicLinkData){// Set up the `onLink` event listener next as it may be received hereif(pendingDynamicLinkData!=null){finalUrideepLink=pendingDynamicLinkData.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}},);runApp(MyApp(initialLink));}
در منطق برنامه خود، می توانید بررسی کنید که آیا یک پیوند مدیریت شده است یا خیر و یک عمل را انجام دهید، به عنوان مثال:
if(initialLink!=null){finalUrideepLink=initialLink.link;// Example of using the dynamic link to push the user to a different screenNavigator.pushNamed(context,deepLink.path);}
پس زمینه / وضعیت پیش زمینه
وقتی برنامه باز است یا در پسزمینه است، از دریافتکننده FirebaseDynamicLinks.onLink استفاده کنید:
از طرف دیگر، اگر میخواهید تشخیص دهید که آیا از یک Dynamic Link دقیق برای باز کردن برنامه استفاده شده است یا خیر، آن را به روش getDynamicLink ارسال کنید:
برای آزمایش یک پیوند پویا در iOS، لازم است که از یک دستگاه واقعی استفاده کنید. همچنین در صورت آزمایش یک پیوند پویا از یک وضعیت برنامه خاتمه یافته (یعنی برنامه بسته شده است.) باید برنامه را در حالت انتشار اجرا کنید (یعنی flutter run --release .).
تاریخ آخرین بهروزرسانی 2025-08-28 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-28 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\n| **Note:** Firebase Dynamic Links is *deprecated* and should not be used in new projects. The service will be shutting down soon. Follow the [migration guide](/support/dynamic-links-faq#how_should_i_migrate_from_the_service) and see the [Dynamic Links Deprecation FAQ](/support/dynamic-links-faq) for more information.\n\nTo receive the Firebase Dynamic Links that [you created](/docs/dynamic-links/create-links),\nyou must include the Dynamic Links SDK in your app and call the\n`FirebaseDynamicLinks.getDynamicLink()` method when your app loads to\nget the data passed in the Dynamic Link.\n\nSet up Firebase and the Dynamic Links SDK\n\n1. [Install and initialize the Firebase SDKs for Flutter](/docs/flutter/setup) if you\n haven't already done so.\n\n2. From the root directory of your Flutter project, run the following\n command to install the Dynamic Links plugin:\n\n flutter pub add firebase_dynamic_links\n\n3. If you're building an Android app, open the [Project settings](https://console.firebase.google.com/project/_/settings/general/)\n page of the Firebase console and make sure you've specified your SHA-1\n signing key. If you use App Links, also specify your SHA-256 key.\n\nPlatform integration\n\nComplete the following platform integration steps for the platforms you're\nbuilding your app for.\n\nAndroid\n\nOn Android, you must add a new intent filter catch deep links of your domain, since the\nDynamic Link will redirect to your domain if your app is installed. This is required for your app to\nreceive the Dynamic Link data after it is installed/updated from the Play Store and one taps on\nContinue button. In `AndroidManifest.xml`: \n\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.VIEW\"/\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\"/\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\"/\u003e\n \u003cdata\n android:host=\"example.com\"\n android:scheme=\"https\"/\u003e\n \u003c/intent-filter\u003e\n\nWhen users open a Dynamic Link with a deep link to the scheme and host you specify, your app will\nstart the activity with this intent filter to handle the link.\n\nThe next step is to ensure the SHA-256 fingerprint of the signing certificate is registered in the Firebase console\nfor the app. You can find more details on how to retrieve your SHA-256 fingerprint on the\n[Authenticating Your Client](https://developers.google.com/android/guides/client-auth) page.\n\nApple platforms\n\n1. [Create an Apple developer account](https://developer.apple.com/programs/enroll/)\n if you don't already have one.\n\n2. On the [Project settings](https://console.firebase.google.com/project/_/settings/general/)\n page of the Firebase console, ensure that your iOS app is correctly\n configured with your App Store ID and Team ID.\n\n3. On the Apple Developer site, create a provisioning profile for your app\n with the Associated Domain capability enabled.\n\n4. In Xcode, do the following:\n\n 1. Open your app under the **TARGETS** header.\n\n 2. On the Signing \\& Capabilities page, ensure your Team is registered, and\n your Provisioning Profile is set.\n\n 3. On the Signing \\& Capabilities page, enable **Associated Domains** and\n add the following to the Associated Domains list (replace example with your domain):\n\n applinks:example.page.link\n\n 4. On the Info page, add a URL Type to your project. Set the URL Schemes\n field to your app's bundle ID. (The Identifier can be `Bundle ID` or\n whatever you wish.)\n\n 5. If you have set up a custom domain for your Firebase project, add the\n Dynamic Link URL prefix into your iOS project's `Info.plist` file\n using the `FirebaseDynamicLinksCustomDomains` key.\n\n \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n \u003c!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"\u003e\n \u003cplist version=\"1.0\"\u003e\n \u003cdict\u003e\n \u003ckey\u003eFirebaseDynamicLinksCustomDomains\u003c/key\u003e\n \u003carray\u003e\n \u003cstring\u003ehttps://custom.domain.io/path1\u003c/string\u003e\n \u003cstring\u003ehttps://custom.domain.io/path2\u003c/string\u003e\n \u003c/array\u003e\n\n ...other settings\n\n \u003c/dict\u003e\n \u003c/plist\u003e\n\n 6. **Optional:** Disable the Dynamic Links SDK's use of the iOS pasteboard.\n\n By default, the Dynamic Links SDK uses the pasteboard to improve the\n reliability of post-install deep links. By using the pasteboard, Dynamic\n Links can make sure that when a user opens a Dynamic Link but needs to\n install your app first, the user can go immediately to the original\n linked content when opening the app for the first time after\n installation.\n\n The downside of this is that use of the pasteboard triggers a\n notification on iOS 14 and later. So, the first time users open your\n app, if the pasteboard contains a Dynamic Link URL, they will see a\n notification that your app accessed the pasteboard, which can cause\n confusion.\n\n To disable this behavior, edit your Xcode project's `Info.plist` file\n and set the `FirebaseDeepLinkPasteboardRetrievalEnabled` key to `NO`.\n | **Note:** When you disable this feature, the Dynamic Links you receive will have a `matchType` of `weak` at best. Adjust your app's logic accordingly.\n\nHandle deep links\n\nTo handle a Dynamic Link in your application, two scenarios require implementing.\n| **Warning:** You may have unexpected results if you have enabled Flutter deep linking in your app. See [Migrating from plugin-based deep linking](https://docs.flutter.dev/development/ui/navigation/deep-linking#migrating-from-plugin-based-deep-linking). This [GitHub issue](https://github.com/firebase/flutterfire/issues/9469) illustrates what you ought to be aware of.\n\nTerminated State\n\nSet up the following methods:\n\n1. `FirebaseDynamicLinks.getInitialLink` - returns a `Future\u003cPendingDynamicLinkData?\u003e`\n2. `FirebaseDynamicLinks.onLink` - event handler that returns a `Stream` containing a `PendingDynamicLinkData?`\n\nAndroid will always receive the link via `FirebaseDynamicLinks.getInitialLink` from a terminated state,\nbut on iOS, it is not guaranteed. Therefore, it is worth setting them both up in the following order\nto ensure your application receives the link: \n\n Future\u003cvoid\u003e main() async {\n WidgetsFlutterBinding.ensureInitialized();\n await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);\n\n // Check if you received the link via `getInitialLink` first\n final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();\n\n if (initialLink != null) {\n final Uri deepLink = initialLink.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n\n FirebaseDynamicLinks.instance.onLink.listen(\n (pendingDynamicLinkData) {\n // Set up the `onLink` event listener next as it may be received here\n if (pendingDynamicLinkData != null) {\n final Uri deepLink = pendingDynamicLinkData.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n },\n );\n\n runApp(MyApp(initialLink));\n }\n\nWithin your application logic, you can then check whether a link was handled and perform an action, for example: \n\n if (initialLink != null) {\n final Uri deepLink = initialLink.link;\n // Example of using the dynamic link to push the user to a different screen\n Navigator.pushNamed(context, deepLink.path);\n }\n\nBackground / Foreground State\n\nWhilst the application is open, or in the background, use the `FirebaseDynamicLinks.onLink`\ngetter: \n\n FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {\n Navigator.pushNamed(context, dynamicLinkData.link.path);\n }).onError((error) {\n // Handle errors\n });\n\nAlternatively, if you wish to identify if an exact Dynamic Link was used to open the application, pass it to\nthe `getDynamicLink` method instead: \n\n String link = 'https://\u003cvar translate=\"no\"\u003edynamic-link-domain\u003c/var\u003e/ke2Qa';\n\n final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getDynamicLink(Uri.parse(link));\n\nTesting A Dynamic Link On iOS Platform\n\nTo test a dynamic link on iOS, it is required that you use an actual device. You will also need to run the app in release mode (i.e. `flutter run --release`.),\nif testing a dynamic link from a terminated (i.e. app has been swiped closed.) app state."]]