تلقّي "روابط Firebase الديناميكية" في تطبيق Flutter
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
لتلقّي روابط Firebase الديناميكية التي أنشأتها، عليك تضمين حزمة تطوير البرامج (SDK) لـ "الروابط الديناميكية" في تطبيقك واستدعاء الطريقة FirebaseDynamicLinks.getDynamicLink() عند تحميل تطبيقك للحصول على البيانات التي تم تمريرها في الرابط الديناميكي.
من الدليل الجذر لمشروع Flutter، شغِّل الأمر التالي لتثبيت المكوّن الإضافي "روابط ديناميكية":
flutter pub add firebase_dynamic_links
إذا كنت بصدد إنشاء تطبيق Android، افتح صفحة إعدادات المشروع في وحدة تحكّم Firebase وتأكَّد من أنّك حدّدت مفتاح التوقيع SHA-1. إذا كنت تستخدم روابط التطبيقات، عليك أيضًا تحديد مفتاح SHA-256.
شريك التكامل
أكمِل خطوات دمج المنصات التالية للمنصات التي تنوي إنشاء تطبيقك عليها.
Android
على نظام التشغيل Android، عليك إضافة فلتر أهداف جديد لتلقّي الروابط المؤدية إلى صفحات معيّنة في نطاقك، لأنّ الرابط الديناميكي سيعيد التوجيه إلى نطاقك إذا كان تطبيقك مثبّتًا. ويجب توفُّر هذا الإعداد لكي يتلقّى تطبيقك بيانات Dynamic Link بعد تثبيته أو تحديثه من "متجر Play" والنقر على الزر "متابعة". في AndroidManifest.xml:
عندما يفتح المستخدمون رابطًا ديناميكيًا يتضمّن رابطًا لصفحة في التطبيق يؤدي إلى المخطط والمضيف اللذين تحدّدهما، سيبدأ تطبيقك النشاط باستخدام فلتر الأهداف هذا للتعامل مع الرابط.
الخطوة التالية هي التأكّد من تسجيل الملف المرجعي لشهادة التوقيع SHA-256 في وحدة تحكّم Firebase للتطبيق. يمكنك العثور على مزيد من التفاصيل حول كيفية استرداد الملف المرجعي لشهادة SHA-256 في صفحة مصادقة العميل.
في صفحة إعدادات المشروع ضمن وحدة تحكّم Firebase، تأكَّد من إعداد تطبيقك على iOS بشكل صحيح باستخدام رقم تعريف App Store ورقم تعريف الفريق.
على موقع Apple Developer الإلكتروني، أنشئ ملفًا تعريفيًا للتزويد لتطبيقك مع تفعيل إمكانية "النطاقات المرتبطة".
في Xcode، اتّبِع الخطوات التالية:
افتح تطبيقك ضمن العنوان الاستهدافات.
في صفحة "التوقيع والقدرات" (Signing & Capabilities)، تأكَّد من تسجيل فريقك وضبط ملف الإعداد (Provisioning Profile).
في صفحة Signing & Capabilities، فعِّل Associated Domains وأضِف ما يلي إلى قائمة Associated Domains (استبدِل example بنطاقك):
applinks:example.page.link
في صفحة "المعلومات"، أضِف نوع عنوان URL إلى مشروعك. اضبط حقل "مخططات عناوين URL" (URL Schemes) على معرّف حزمة تطبيقك. (يمكن أن يكون المعرّف Bundle ID أو أي قيمة أخرى تريدها).
إذا كنت قد أعددت نطاقًا مخصّصًا لمشروعك على Firebase، أضِف بادئة عنوان URL للرابط الديناميكي إلى ملف Info.plist في مشروع iOS باستخدام المفتاح FirebaseDynamicLinksCustomDomains.
اختياري: أوقِف استخدام حزمة تطوير البرامج (SDK) للروابط الديناميكية في لوحة النسخ واللصق على أجهزة iOS.
تستخدِم حزمة تطوير البرامج (SDK) لـ Dynamic Links الحافظة تلقائيًا لتحسين موثوقية الروابط لصفحات معيّنة في التطبيق بعد التثبيت. باستخدام الحافظة، يمكن للروابط الديناميكية التأكّد من أنّه عندما يفتح أحد المستخدمين رابطًا ديناميكيًا ولكن يحتاج إلى تثبيت تطبيقك أولاً، يمكن للمستخدم الانتقال مباشرةً إلى المحتوى الأصلي المرتبط عند فتح التطبيق لأول مرة بعد التثبيت.
أما الجانب السلبي لذلك، فهو أنّ استخدام الحافظة يؤدي إلى ظهور إشعار على نظام التشغيل iOS 14 والإصدارات الأحدث. لذلك، عندما يفتح المستخدمون تطبيقك للمرة الأولى، إذا كانت الحافظة تحتوي على عنوان URL لرابط ديناميكي، سيظهر لهم إشعار بأنّ تطبيقك وصل إلى الحافظة، ما قد يسبب إرباكًا.
لإيقاف هذا السلوك، عدِّل ملف Info.plist في مشروع Xcode واضبط قيمة المفتاح FirebaseDeepLinkPasteboardRetrievalEnabled على NO.
التعامل مع الروابط المؤدية إلى صفحات في التطبيق
للتعامل مع رابط ديناميكي في تطبيقك، يجب تنفيذ سيناريوهَين.
الحالة "تم إنهاؤه"
اضبط الطرق التالية:
FirebaseDynamicLinks.getInitialLink - تعرض Future<PendingDynamicLinkData?>
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
getter:
لاختبار رابط ديناميكي على نظام التشغيل 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."]]