ios
android
Before you begin
ios
Before you begin, you need a few things set up in your environment:
- An app with Firebase enabled: If you haven't already, add Firebase to your iOS project.
- Xcode 9.2 or higher: Firebase In-App Messaging needs a relativley-recent version of Xcode to run. You can find the latest Xcode version at Apple's Xcode site.
- CocoaPods 1.4.0 or higher: Firebase In-App Messaging uses CocoaPods to manage dependencies on iOS. You can install it from the CocoaPods site.
android
To get started, your app needs to meet two requirements:
- Firebase enabled: If you haven't already, add Firebase to your Android project.
- Minimum Android SDK of 16 or higher: Check your app-level
build.gradle
for theminSdkVersion
, which must be set to at least 16.
Add the Firebase In-App Messaging SDK to your project
ios
To get started, add the Firebase In-App Messaging SDK framework files to your project by adding the Firebase In-App Messaging CocoaPods:
- Open a new terminal window, and navigate to your Xcode project's directory.
- Open your Podfile, and add the highlighted lines:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'YourProject' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for YourProject pod 'Firebase' pod 'Firebase/InAppMessagingDisplay' end
- From your terminal, install the pod's dependencies:
pod install
- Open your app's project in Xcode:
open YOUR-PROJECT.xcworkspace
- Import the Firebase module in your
UIApplicationDelegate
, if you haven't yet:Swift
import Firebase
Objective-C
@import Firebase;
- Also configure a
FirebaseApp
shared instance, typically in your app'sapplication:didFinishLaunchingWithOptions:
method, if you haven't yet:Swift
// Use Firebase library to configure APIs FirebaseApp.configure()
Objective-C
// Use Firebase library to configure APIs [FIRApp configure];
- Compile and run your app.
android
Include the SDK in your build files
Add the In-App Messaging dependency to your app-level build.gradle
:
// ... dependencies { // ... // Add the In-App Messaging dependency: implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.5' // Check that your Firebase dependency is up-to-date: implementation 'com.google.firebase:firebase-core:16.0.7' }
Send a test message
Get your app's Instance ID
To conserve power, Firebase In-App Messaging only retrieves messages from the server once per day. That can make testing difficult, so the Firebase console allows you to specify a test device that displays messages on demand.
ios
That testing device is determined by a FirebaseInstanceID
.
To find your testing app's Instance ID, run the app with the runtime command
argument -FIRDebugEnabled
:
- With your Xcode project open, select Product > Scheme > Edit scheme... from the top menu bar.
- Open the Arguments tab of the dialog that pops up.
- Click + Add items under Arguments Passed On Launch.
- Enter "-FIRDebugEnabled" in the newly-created field.
- Click Close, then run your app.
Once your app starts running, look for the following line in the Xcode console's logs:
[Firebase/InAppMessaging][I-IAM180017] Starting InAppMessaging runtime with Instance ID YOUR_APP_ID
android
That testing device is determined by a FirebaseInstanceId
.
Find your testing app's Instance ID by checking the Logcat in Android Studio for the following
`Info` level log:
I/FIAM.Headless: Starting InAppMessaging runtime with Instance ID YOUR_APP_ID
Send a message to your testing device
Once you've launched your app on the testing device and you have its Instance ID, you can try out Firebase In-App Messaging set up by sending a test message:
- In the Firebase console, open In-App Messaging.
- Once there, click New Campaign.
- Enter a Title for your first message.
- Click Test on your Device
- Enter your app's Instance ID in the Add an instance ID field.
- Click Test to send the message.
Firebase In-App Messaging sends your test message as soon as you click Test. To see it, close, then reopen the app on your testing device.