This quickstart shows you how to set up Firebase In-App Messaging and send your first message.
Before you begin
Before starting, make sure to
add Firebase to your Apple project
.
Add the Firebase In-App Messaging SDK to your project
Use Swift Package Manager to install and manage Firebase dependencies.
- In Xcode, with your app project open, navigate to
File > Add Packages
.
- When prompted, add the Firebase Apple platforms SDK repository:
https://github.com/firebase/firebase-ios-sdk.git
- Choose the In-App Messaging library.
- Add the
-ObjC
flag to the
Other Linker Flags
section of your target's build settings.
-
To use In-App Messaging, you must
enable Google Analytics
in your Firebase project and add the Firebase SDK for Google Analytics to your app. You can select
either the library without IDFA collection or with IDFA collection.
-
When finished, Xcode will automatically begin resolving and downloading your
dependencies in the background.
Now, initialize the SDK in your app:
- Import the Firebase module in your
App
struct or
UIApplicationDelegate
, if you haven't yet:
Objective-C
@import Firebase;
- Also configure a
FirebaseApp
shared instance, typically in your
App
's initializer or your app delegate's
application(_:didFinishLaunchingWithOptions:)
method, if you haven't yet:
Swift
FirebaseApp.configure()
Objective-C
[FIRApp configure];
- Compile and run your app.
Send a test message
Get your app's installation 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.
That testing device is determined by a Firebase installation ID provided by the
Firebase installations service. To find your testing app's installation 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 Firebase Installation ID
YOUR_INSTALLATION_ID
Send a message to your testing device
Once you've launched your app on the testing device and you have its
Firebase installation ID (FID), you can try out your Firebase In-App Messaging
setup by sending a test message:
- In the Firebase console, open the
Messaging page
.
- If this is your first campaign, click
Create your first campaign
.
- Select
Firebase In-App messages
and click
Create
.
- Otherwise, on the
Campaigns
tab, click
New campaign
.
- Select
In-App Messaging
.
- Enter a
Title
for your first message.
- Click
Test on Device
- Enter your app's Firebase installation ID in the
Add an installation ID
field.
- Click
Test
to send the message.
Firebase In-App Messaging sends your test message as soon as you click
Test
. To see the
message, you need to close, then reopen the app on your testing device.
To confirm whether your device is a test device, look for the following
log message:
[Firebase/InAppMessaging][I-IAM180017] Seeing test message in fetch response. Turn the current instance into a testing instance.