Receive Dynamic Links with C++

To receive the Firebase Dynamic Links that you created, you must include the Dynamic Links SDK in your app and create a firebase::dynamic_links::Listener object that implements the OnDynamicLinkReceived virtual function.

The C++ SDK works for both Android and iOS, with some additional setup required for each platform.

Before you begin

Android

  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your Android project.
  3. Add the dependency for Firebase Dynamic Links to your app-level build.gradle file:
    dependencies {
         compile 'com.google.firebase:firebase-invites:11.6.2'
    }
  4. Link the libapp.a and libdynamic_links.a static library, from the C++ SDK.

iOS

  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your iOS project.
  3. 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:
    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.
    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.
    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.app, 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 > Bundle Identifier).
  4. Include the following Pod in your Podfile:
    pod 'Firebase/DynamicLinks'
  5. Run pod install
  6. Add firebase.framework and firebase_dynamic_links.framework, from the C++ SDK, to your Xcode project.

Receiving a Dynamic Link

Create and initialize App

Before you can check for received Dynamic Links, you'll need to create and initialize a firebase::App object.

Include the header file for firebase::App:

#include "firebase/app.h"

The next part varies depending on your platform:

Android

Create the firebase::App, passing the JNI environment and a jobject reference to the Java Activity as arguments:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"), jni_env, activity);

iOS

Create the firebase::App:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"));

Implement Listener to check for Dynamic Links

To check for a received Dynamic Link, implement and use the firebase::dynamic_links::Listener class.

Include the header file for receiving Dynamic Links:

#include "firebase/dynamic_links.h"

Initialize the Dynamic Links library:

::firebase::dynamic_links::Initialize(app, null);

Create an object that implements firebase::dynamic_links::Listener, and supply it to the Dynamic Links library with SetListener(), or pass it as the second argument to Initialize.

To receive Dynamic Links, your Listener class must implement the OnDynamicLinkReceived virtual function. By overriding the method, you can receive a deep link, if one was received.

class Listener : public firebase::dynamic_links::Listener {
 public:
  // Called on the client when a dynamic link arrives.
  void OnDynamicLinkReceived(
      const firebase::dynamic_links::DynamicLink* dynamic_link) override {
    printf("Received link: %s", dynamic_link->url.c_str());
  }
};

Send feedback about...

Need help? Visit our support page.