if(result.status()==firebase::kFutureStatusComplete){if(result.error()==firebase::dynamic_links::kErrorCodeSuccess){firebase::dynamic_links::GeneratedDynamicLinklink=*result.result();printf("Create short link succeeded: %s\n",link.url.c_str());}else{printf("Created short link failed with error '%s'\n",result.error_message());}}
[[["易于理解","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"]],["最后更新时间 (UTC):2025-09-04。"],[],[],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\nYou can create short or long Dynamic Links with the Firebase Dynamic Links API. The API\ntakes several optional parameter structures to build links. Short links can\nalso be created from a previously generated long link. Firebase Dynamic Links\ngenerates a URL like the following: \n\n https://example.page.link/WXYZ\n\nThe C++ SDK works for both Android and iOS, with some additional setup required\nfor each platform.d\n\nBefore you begin\n\nBefore you can use\n[Firebase Dynamic Links](/docs/reference/unity/namespace/firebase/dynamic-links),\nyou need to:\n\n- Register your C++ project and configure it to use Firebase.\n\n If your C++ project already uses Firebase, then it's already registered and\n configured for Firebase.\n- Add the [Firebase C++ SDK](/download/cpp) to your C++ project.\n\n| **Find detailed instructions for these initial\n| setup tasks in\n| [Add Firebase to your C++\n| project](/docs/cpp/setup#note-select-platform).**\n\nNote that adding Firebase to your C++ project involves tasks both in the\n[Firebase console](//console.firebase.google.com/) and in your open C++ project (for example, you download\nFirebase config files from the console, then move them into your C++ project). \n\nAndroid\n\n1. In the Firebase console, open the **Dynamic Links** section.\n2. If you have not already accepted the terms of service and set a URI\n prefix for your Dynamic Links, do so when prompted.\n\n If you already have a Dynamic Links URI prefix, take note of it. You need\n to provide a Dynamic Links URI prefix when you programmatically create\n Dynamic Links.\n\n3. **Recommended** : Specify the URL patterns allowed in your deep links and fallback links. By doing so, you prevent unauthorized parties from creating Dynamic Links that redirect from your domain to sites you don't control. See [Allow specific URL patterns](/docs/dynamic-links/allow-specific-url-patterns).\n\niOS\n\n1. In the Firebase console, open the **Dynamic Links** section.\n2. If you have not already accepted the terms of service and set a URI\n prefix for your Dynamic Links, do so when prompted.\n\n If you already have a Dynamic Links URI prefix, take note of it. You need\n to provide a Dynamic Links domain when you programmatically create\n Dynamic Links.\n\n3. The Firebase Dynamic Links C++ client library uses custom URL schemes on iOS to process links. You must add custom URL schemes to your app to support receiving Dynamic Links:\n 1. To open your project configuration, double-click the project name in the left tree view. Select your app from the **TARGETS** section, then select the **Info** tab, and expand the **URL Types** section.\n 2. Click the **+** button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the `REVERSED_CLIENT_ID` key. Copy the value of that key, and paste it into the **URL Schemes** box on the configuration page. Leave the other fields blank.\n 3. Click the **+** button, and add a second URL scheme. This one is the same as your app's bundle ID. For example, if your bundle ID is `com.example.ios`, type that value into the **URL Schemes** box. You can find your app's bundle ID in the **General** tab of the project configuration (**Identity \\\u003e Bundle Identifier**).\n\n| **Note:** Dynamic Links is not supported on tvOS.\n\nUse the Firebase console\n\nIf you want to generate a single Dynamic Link, either for testing purposes, or for your marketing team\nto easily create a link that can be used in something like a social media post, the simplest way would\nbe to visit the [Firebase console](https://console.firebase.google.com/project/_/durablelinks/links/)\nand create one manually following the step-by-step form.\n\nCustom domains\n\nYou can have greater control over your Dynamic Link's branding by using your own\ndomain instead of a `goo.gl` or `page.link` subdomain. Follow [these\ninstructions](/docs/dynamic-links/custom-domains) to set up a custom domain for\nyour project.\n| **Note:** If you're building your project for iOS, you must edit the `Info.plist` file per the [iOS-only instructions](/docs/dynamic-links/custom-domains#console) for setting up a custom domain.\n\nUsing the Firebase Dynamic Links API\n\nCreate and initialize App\n\nBefore you can create Dynamic Links, you'll need to create and initialize\na [`firebase::App`](/docs/reference/cpp/class/firebase/app) object.\n| You only need to initialize firebase::App once, no matter how many Firebase C++ features you use.\n\nInclude the header file for `firebase::App`: \n\n```c++\n#include \"firebase/app.h\"\n```\n\nThe next part varies depending on your platform: \n\nAndroid\n\n\nCreate the `firebase::App`, passing the JNI environment and a `jobject`\nreference to the Java Activity as arguments: \n\n```c++\napp = ::firebase::App::Create(::firebase::AppOptions(\"APPLICATION NAME\"), jni_env, activity);\n```\n\niOS\n\n\nCreate the `firebase::App`: \n\n```c++\napp = ::firebase::App::Create(::firebase::AppOptions(\"APPLICATION NAME\"));\n```\n\nInitialize Dynamic Links library\n\nBefore creating a Dynamic Link, you must first\n[initialize](/docs/reference/cpp/namespace/firebase/dynamic-links#initialize)\nthe Dynamic Links library: \n\n```c++\n::firebase::dynamic_links::Initialize(app, null);\n```\n\n\u003cbr /\u003e\n\nCreating a long Dynamic Link from parameters\n\nTo create a Dynamic Link, create a DynamicLinkComponents object, setting any of\nthe optional members for additional configuration, and passing it to\n`dynamic_links::GetShortLink` or `dynamic_links::GetLongLink`.\n\nThe following minimal example creates a long Dynamic Link to\nhttps://www.example.com/ that opens with your Android app\ncom.example.android.package_name and iOS app com.example.ios: \n\n```c++\nfirebase::dynamic_links::IOSParameters ios_parameters(\"com.example.ios\");\n\nfirebase::dynamic_links::AndroidParameters android_parameters(\n \"com.example.android.package_name\");\n\nfirebase::dynamic_links::DynamicLinkComponents components(\n \"https://www.example.com/\", \"example.page.link\");\ncomponents.android_parameters = &android_parameters;\ncomponents.ios_parameters = &ios_parameters;\n\nfirebase::dynamic_links::GeneratedDynamicLink long_link =\n firebase::dynamic_links::GetLongLink(components);\n```\n| **Note:** Long Links append all of the configuration settings as query arguments to the link and therefore do not require any network calls.\n\nCreating a short Dynamic Link\n\nTo create a short Dynamic Link, pass a previously generated long link to\n`GetShortLink` or build `DynamicLinkComponents` the same way as above.\n\n`GetShortLink` optionally takes an extra `DynamicLinkOptions` config\nparameter with `PathLength`; this allows you to control how the link should be\ngenerated. Generating a short link requires a network request to the Firebase\nbackend, so `GetShortLink` is asynchronous, returning a `Future\u003cGeneratedLink\u003e`.\n\nFor example: \n\n```c++\nfirebase::dynamic_links::DynamicLinkOptions short_link_options;\nshort_link_options.path_length = firebase::dynamic_links::kPathLengthShort;\n\nfirebase::Future\u003cfirebase::dynamic_links::GeneratedDynamicLink\u003e result =\n firebase::dynamic_links::GetShortLink(components, short_link_options);\n```\n\nIf your program has an update loop that runs regularly (say at 30 or 60 times\nper second), you can check the results once per update: \n\n```c++\nif (result.status() == firebase::kFutureStatusComplete) {\n if (result.error() == firebase::dynamic_links::kErrorCodeSuccess) {\n firebase::dynamic_links::GeneratedDynamicLink link = *result.result();\n printf(\"Create short link succeeded: %s\\n\", link.url.c_str());\n } else {\n printf(\"Created short link failed with error '%s'\\n\",\n result.error_message());\n }\n}\n```"]]