To create Firebase Dynamic Links, include the Dynamic Links SDK in your app and use theFIRDynamicLinkComponents.url
parameter.
Prerequisites
Firebase Dynamic Links requires iOS 8 or newer. You can target iOS 7 in your app, but Firebase Dynamic Links SDK calls only function on apps running iOS 8 or newer.
Set up Firebase and the Dynamic Links SDK
- Add Firebase to your iOS project. Include the following pod in your
Podfile
: pod 'Firebase/DynamicLinks' - Run
pod install
and open the created.xcworkspace
file. - In the Firebase console, open the Dynamic Links section.
- Accept the terms of service if you are prompted to do so.
- Take note of your project's Dynamic Links domain, which is displayed at the top of the Dynamic Links page. You need your project's Dynamic Links domain to programmatically create Dynamic Links. A Dynamic Links domain looks like this:
app_code.app.goo.gl
.
Ensure that your app's App Store ID and your App ID prefix is specified in your app's settings. To view and edit your app's settings, go to your Firebase project's Settings page and select your iOS app.
Confirm that your Firebase project is properly configured to use Dynamic Links in your iOS app by opening the following URL:
https://app_code.app.goo.gl/apple-app-site-associationIf your app is connected, the
{"applinks":{"apps":[],"details":[{"appID":"1234567890.com.example.ios","paths":["/*"]}]}}apple-app-site-association
file contains a reference to your app's App Store ID and bundle ID. For example:If the
details
field is empty, double-check that you specified your App ID prefix. Note that your App ID prefix may not be the same as your Team ID.
Add Firebase to your app
- Import the Firebase module in your
UIApplicationDelegate
:@import Firebase ; - Configure a
FirebaseApp
shared instance, typically in your application'sapplication:didFinishLaunchingWithOptions:
method:// Use Firebase library to configure APIs
[ FIRApp configure ];
Use the Firebase console
If you want to generate a single Dynamic Link, either for testing purposes, or for your marketing team to easily create a link that can be used in something like a social media post, the simplest way to would be to visit the Firebase console and create one manually following the step-by-step form.
Use the iOS Builder API
You can create short or long Dynamic Links with the Firebase Dynamic Links iOS Builder API. This API accepts either a long Dynamic Link or an object containing Dynamic Link parameters, and returns a URL like the following example:
https://abc123.app.goo.gl/WXYZCreate a long link from parameters
You can create a Dynamic Link programmatically by setting the following parameters and getting the FIRDynamicLinkComponents.url
parameter.
if ( _dictionary [ Link ]. text == nil ) {
NSLog (@ "%@" , @ "Link can not be empty!" );
return ;
}
NSURL * link = [ NSURL URLWithString : _dictionary [ Link ]. text ];
FIRDynamicLinkComponents * components =
[ FIRDynamicLinkComponents componentsWithLink : link
domain : DYNAMIC_LINK_DOMAIN ];
// analytics params
FIRDynamicLinkGoogleAnalyticsParameters * analyticsParams =
[ FIRDynamicLinkGoogleAnalyticsParameters parametersWithSource : _dictionary [ Source ]. text
medium : _dictionary [ Medium ]. text
campaign : _dictionary [ Campaign ]. text ];
analyticsParams . term = _dictionary [ Term ]. text ;
analyticsParams . content = _dictionary [ Content ]. text ;
components . analyticsParameters = analyticsParams ;
if ( _dictionary [ BundleID ]. text ) {
// iOS params
FIRDynamicLinkIOSParameters * iOSParams = [ FIRDynamicLinkIOSParameters parametersWithBundleID : _dictionary [ BundleID ]. text ];
iOSParams . fallbackURL = [ NSURL URLWithString : _dictionary [ FallbackURL ]. text ];
iOSParams . minimumAppVersion = _dictionary [ MinimumAppVersion ]. text ;
iOSParams . customScheme = _dictionary [ CustomScheme ]. text ;
iOSParams . iPadBundleID = _dictionary [ IPadBundleID ]. text ;
iOSParams . iPadFallbackURL = [ NSURL URLWithString : _dictionary [ IPadFallbackURL ]. text ];
iOSParams . appStoreID = _dictionary [ AppStoreID ]. text ;
components . iOSParameters = iOSParams ;
// iTunesConnect params
FIRDynamicLinkItunesConnectAnalyticsParameters * appStoreParams = [ FIRDynamicLinkItunesConnectAnalyticsParameters parameters ];
appStoreParams . affiliateToken = _dictionary [ AffiliateToken ]. text ;
appStoreParams . campaignToken = _dictionary [ CampaignToken ]. text ;
appStoreParams . providerToken = _dictionary [ ProviderToken ]. text ;
components . iTunesConnectParameters = appStoreParams ;
}
if ( _dictionary [ PackageName ]. text ) {
// Android params
FIRDynamicLinkAndroidParameters * androidParams = [ FIRDynamicLinkAndroidParameters parametersWithPackageName : _dictionary [ PackageName ]. text ];
androidParams . fallbackURL = [ NSURL URLWithString : _dictionary [ FallbackURL ]. text ];
androidParams . minimumVersion = ( _dictionary [ MinimumVersion ]. text ). integerValue ;
components . androidParameters = androidParams ;
}
// social tag params
FIRDynamicLinkSocialMetaTagParameters * socialParams = [ FIRDynamicLinkSocialMetaTagParameters parameters ];
socialParams . title = _dictionary [ Title ]. text ;
socialParams . descriptionText = _dictionary [ DescriptionText ]. text ;
socialParams . imageURL = [ NSURL URLWithString : _dictionary [ ImageURL ]. text ];
components . socialMetaTagParameters = socialParams ;
// OtherPlatform params
FIRDynamicLinkOtherPlatformParameters * otherPlatformParams =
[ FIRDynamicLinkOtherPlatformParameters parameters ];
otherPlatformParams . fallbackUrl = [ NSURL URLWithString : _dictionary [ OtherFallbackURL ]. text ];
components . otherPlatformParameters = otherPlatformParams ;
_longLink = components . url ;
NSLog (@ "Long URL: %@" , _longLink . absoluteString );
Set the length of a short Dynamic Link
You can also set the pathLength
parameter to specify how the path component of the short Dynamic Link is generated.
options . pathLength = FIRShortDynamicLinkPathLengthUnguessable ;
components . options = options ;
By default, or if you set the parameter to "UNGUESSABLE"
, the path component will be a 17-character string, like in the following example:
Such strings are created by base62-encoding randomly generated 96-bit numbers. Use this setting to prevent your Dynamic Links URLs from being guessed and crawled, which can potentially expose sensitive information to unintended recipients.
If you set the parameter to "SHORT"
, the path component will be a string that is only as long as needed to be unique, with a minimum length of 4 characters.
Use this method if sensitive information would not be exposed if a short Dynamic Link URL were guessed.
Create a short link from a long link
You can use the Firebase Dynamic Links API to shorten a long Dynamic Link. To do so, call
NSArray * _Nullable warnings ,
NSError * _Nullable error ) {
// Handle shortURL or error.
if ( error ) {
NSLog (@ "Error generating short link: %@" , error . description );
return ;
}
_shortLink = shortURL ;
NSLog (@ "Short URL: %@" , _shortLink . absoluteString );
// ...
}];
Specifying a custom URL scheme for Dynamic Links
By default, Dynamic Links uses your app's bundle identifier as the URL scheme needed to open up your application. We recommend staying with this default value to keep your implementation simple.
However, developers who are already using a custom URL scheme for other purposes may wish to use this same custom URL scheme for their Dynamic Links as well. If you are in this situation, you can specify a different URL scheme for your Firebase Dynamic Links by following these steps:
- When setting up your app, make sure you specify the default URL scheme to be used by your application before configuring your
FirebaseApp
shared instance:- ( BOOL ) application :( UIApplication *) application
didFinishLaunchingWithOptions :( NSDictionary *) launchOptions {
// Set deepLinkURLScheme to the custom URL scheme you defined in your
// Xcode project.
[ FIROptions defaultOptions ]. deepLinkURLScheme = CUSTOM_URL_SCHEME ;
[ FIRApp configure ];
return YES ;
} - Whenever you create any Dynamic Link, you will need to specify the custom URL scheme that your app uses. You can do this through the Firebase console, setting the
customScheme
in the Builder API, specifying theius
parameter in your URL, or sending theiosCustomScheme
parameter to the REST API
Next steps
Now that you've created Dynamic Links, you need to set up your app to receive Dynamic Links and send users to the right place in your app after a user opens them.
To receive Dynamic Links in your app, see the documentation for iOS, Android, C++, and Unity.