To receive the Firebase Dynamic Links that you created,
you must include the Dynamic Links SDK in your app and create a
firebase::invites::Listener
object that implements the
OnInviteReceived
virtual function.
The C++ SDK works for both Android and iOS, with some additional setup required for each platform.
Before you begin
Android
- If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
- Add Firebase to your Android project.
- Add the dependency for Firebase Invites to your app-level
build.gradlefile:dependencies { compile 'com.google.firebase:firebase-invites:10.0.1' } - Link the
libapp.aandlibinvites.astatic library, from the C++ SDK.
iOS
- If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
- Add Firebase to your iOS project.
- The Firebase Invites 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:
- 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.
- Click the + button, and add a URL scheme for your reversed client
ID. To find this value, open the
GoogleService-Info.plistconfiguration file, and look for theREVERSED_CLIENT_IDkey. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank. - 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).
- Include the following Pod in your
Podfile:pod 'Firebase/Invites'
- Run
pod install - Add
firebase.frameworkandfirebase_invites.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
The Firebase Invites C++ library is also used for
receiving Dynamic Links. To check for a received Dynamic Link, implement and use the
firebase::invites::Listener
class.
Include the header file for receiving Invites:
#include "firebase/invites.h"
Initialize the Invites library:
::firebase::invites::Initialize(app);
Create an object that implements
firebase::invites::Listener,
and supply it to the Invites library with
SetListener().
To receive invitations, your Listener class must implement the
OnInviteReceived
virtual function. By overriding the method, you can receive a deep link, if
one was received.
void OnInviteReceived(const char* invitation_id, const char* deep_link,
bool is_strong_match) override {
if (deep_link != nullptr) {
// The app received a Dynamic Link. This may have come from an invitation
// (if invite.invitation_id is set), or it might have been sent using
// Firebase Dynamic Links.
// In any event, the app can now act on this link as you see fit.
}
if (invitation_id != nullptr) {
// We received an invitation ID. See the Firebase Invites documentation
// for more information.
}
}

