create firebase dynamic links

Create Dynamic Links on iOS

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

  1. Add Firebase to your iOS project. Include the following pod in your Podfile:
     
       
    pod 'Firebase/DynamicLinks'
  2. Run pod install and open the created .xcworkspace file.
  3. In the Firebase console, open the Dynamic Links section.
    1. Accept the terms of service if you are prompted to do so.
    2. 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.

  4. 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-association

    If your app is connected, the apple-app-site-association file contains a reference to your app's App Store ID and bundle ID. For example:

     
       
    {"applinks":{"apps":[],"details":[{"appID":"1234567890.com.example.ios","paths":["/*"]}]}}

    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

  1. Import the Firebase module in your UIApplicationDelegate:
    SWIFT
    OBJECTIVE-C
     
        
    @import Firebase ;
  2. Configure a FirebaseApp shared instance, typically in your application's application:didFinishLaunchingWithOptions: method:
    SWIFT
    OBJECTIVE-C
     
        
    // 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/WXYZ

Create a long link from parameters

You can create a Dynamic Link programmatically by setting the following parameters and getting the FIRDynamicLinkComponents.url parameter.

SWIFT
OBJECTIVE-C
 
  
// general link params
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.

SWIFT
OBJECTIVE-C
 
  
FIRDynamicLinkComponentsOptions * options = [ FIRDynamicLinkComponentsOptions options ];
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:

 
 
https://abc123.app.goo.gl/UVWXYZuvwxyz12345

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.

 
 
https://abc123.app.goo.gl/WXYZ

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

SWIFT
OBJECTIVE-C
 
  
[ components shortenWithCompletion :^( NSURL * _Nullable shortURL ,
                                   
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:

  1. 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:
    SWIFT
    OBJECTIVE-C
     
        
    - ( 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 ;
    }
  2. 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 the ius parameter in your URL, or sending the iosCustomSchemeparameter 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 iOSAndroidC++, and Unity.


Firebase Dynamic Links是一种用于在应用程序和网站之间传递数据的服务。在Android端触发跳转到应用程序的步骤如下: 1. 确保应用程序已经与Firebase项目绑定,并且已经配置了Firebase Dynamic Links。 2. 在AndroidManifest.xml文件中,添加一个intent过滤器,以便应用程序可以处理Firebase Dynamic Links: ```xml <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="example.com" android:scheme="https" /> </intent-filter> ``` 其中,android:host和android:scheme应该设置为Firebase Dynamic Links中用于您的应用程序的域名和协议。例如,如果您的Firebase Dynamic Links域名是example.page.link,则应将android:host设置为example.page.link,将android:scheme设置为https。 3. 在应用程序中,使用Firebase Dynamic Links API来处理传入链接并触发应用程序的操作: ```java FirebaseDynamicLinks.getInstance() .getDynamicLink(getIntent()) .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() { @Override public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) { Uri deepLink = null; if (pendingDynamicLinkData != null) { deepLink = pendingDynamicLinkData.getLink(); } // 处理deepLink并触发应用程序的操作 } }) .addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { // 处理失败情况 } }); ``` 在addOnSuccessListener中,您可以使用PendingDynamicLinkData对象获取传入链接的深层链接,并使用它来触发应用程序的操作。如果没有传入链接或获取链接失败,则addOnFailureListener将被调用。 希望这可以回答您的问题!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值