InviteReceived
event.
The Unity SDK works for both Android and iOS, with some additional setup required for each platform.
Before you begin
Before you can use Firebase Dynamic Links, you will need to create a Firebase project, and add the Firebase Unity SDK packages to your Unity project.
Setup:
Prerequisites
Android
- Unity 5.0 or later.
- Android NDK version 10d or later.
iOS
- Unity 5.0 or later.
- Xcode 8.0 or later.
- A physical iOS device
- APNs certificate with Push Notifications enabled
If you don't have a Unity project already, you can download one of our quickstart samples and experiment with a specific Firebase feature. If you're using a quickstart, remember to get the bundle identifier from the project settings; you'll need it for the next step.
Set up your app in Firebase console
To add Firebase to your app you'll need a Firebase project and a Firebase configuration file for your app.
Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
Android
- Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
- When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.
- Download a
google-services.jsonfile when instructed. You can redownload this file again at any time. - Copy this file to anywhere inside your project's assets folder.
IOs
- Click Add Firebase to your iOS app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
- When prompted, enter your app's bundle ID. It's important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project.
- Download a
GoogleService-Info.plistfile when instructed. You can redownload this file again at any time. Add the
GoogleService-Info.plistfile to the project.Drag the
GoogleService-Info.plistdownloaded from the Firebase console into any folder in the Unity project.
Add the Firebase Unity SDK to your app
- Download the Firebase Unity SDK
- Select the Assets > Import Package > Custom Package menu item.
- Import the
FirebaseInvites.unitypackagepackage from the Firebase Unity SDK, downloaded previously. - When the Import Unity Package window appears, click the Import button.
Build your app
Android
- Select the File > Build Settings menu option.
- Select Android in the Platform list.
- Click Switch Platform to select Android as the target platform.
- Wait for the spinner (compiling) icon in the bottom right corner of the Unity status bar to stop.
- Click Build and Run.
iOS
- Select the File > Build Settings menu option.
- Select iOS in the Platform list.
- Click Switch Platform to select iOS as the target platform.
- Wait for the spinner (compiling) icon in the bottom right corner of the Unity status bar to stop.
Click Build and Run.
After Xcode opens, add the UserNotifications.framework.
- Click on the project in Xcode and select the General tab from the Editor area.
- Scroll down to Linked Frameworks and Libraries and click the + button to add a framework.
- In the window that appears, scroll to UserNotifications.framework and click on that entry, then click on Add.
Register to receive incoming Dynamic Links
To check for Dynamic Links, you need to register for the
InviteReceived
event.
void Start() {
var app = Firebase.FirebaseApp.Create();
Firebase.Invites.FirebaseInvites.InviteReceived += OnInviteReceived;
Firebase.Invites.FirebaseInvites.InviteNotReceived += OnInviteNotReceived;
Firebaes.Invites.FirebaseInvites.ErrorReceived += OnErrorReceived;
}
void OnInviteReceived(object sender,
Firebase.Invites.InviteReceivedEventArgs e) {
if (e.InvitationId != "") {
Debug.Log("Invite received: Invitation ID: " + e.InvitationId);
Firebase.Invites.FirebaseInvites.ConvertInvitationAsync(
e.InvitationId).ContinueWith(HandleConversionResult);
}
if (e.DeepLink != "") {
Debug.Log("Invite received: Deep Link: " + e.DeepLink);
}
}
void OnInviteNotReceived(object sender, System.EventArgs e) {
Debug.Log("No Invite or Deep Link received on start up");
}
void OnErrorReceived(object sender,
Firebase.Invites.InviteErrorReceivedEventArgs e) {
Debug.LogError("Error occurred received the invite: " + e.ErrorMessage);
}

