Welcome to the Grow Friendly Chat codelab. In this codelab, you'll learn how to use the Firebase platform to grow iOS applications. You will take a working chat app to the next level, growing your user base and improving their experience.
This codelab is also available in Objective-C.
Clone the GitHub repository from the command line.
$ git clone https://github.com/firebase/codelab-friendlychat-ios
To build the starter app:
grow-ios-starter/swift-starter
directory from your sample code download pod install
Firebase In-App Messaging helps you engage your app's active users by sending them targeted, contextual messages that encourage them to use key app features.
Confirm the pod 'Firebase/InAppMessagingDisplay'
dependency exists in your Podfile
file.
Device testing requires a FirebaseInstanceID. Find your testing app's Instance ID by running the app with the runtime command argument -FIRDebugEnabled, and looking for the following line in the Xcode console's logs:
[Firebase/InAppMessaging][I-IAM180017] Starting InAppMessaging runtime with Instance ID YOUR_APP_ID
Go to Product > Scheme > Edit Scheme. Then select the Arguments tab and add the flag to `Arguments passed on launch`
Click the Run button. Then search for the line with "Starting InAppMessaging" in the Xcode console. Make note of the Instance ID.
From the Firebase console, select `In-App Messaging` from the navigation panel. Select `Start your first campaign`. Enter "Welcome back" for the title and "Good to see you again" for the body. Then click Test on your Device. Enter the Instance ID in the available field and click the + sign to add it. Then click Test.
Firebase Analytics provides a way for you to understand the way users move through your application, where they succeed and where they get stuck and turn back. It can also be used to understand the most used parts of your application.
Add measurement helper methods.
static func sendLoginEvent() {
Analytics.logEvent(AnalyticsEventLogin, parameters: nil)
}
static func sendLogoutEvent() {
Analytics.logEvent("logout", parameters: nil)
}
static func sendMessageEvent() {
Analytics.logEvent("message", parameters: nil)
}
If you want to view this activity in your Firebase console, select Product ... Scheme... Edit Scheme in Xcode. In the Arguments Passed on Launch section, click the + to add a new argument and add add -FIRAnalyticsDebugEnabled as the new argument.
Firebase Crashlytics allows your application to report when crashes occur and log the events leading up to the crash.
Setup Crashlytics in the Firebase console. Select the Crashlytics item in the Quality section. Then select Setup Crashlytics then the "new to Crashlytics" option and hit next.
Confirm that pod 'Fabric', '~> 1.7.2' and pod 'Crashlytics', '~> 3.9.3' dependencies exist in your Podfile file.
${PODS_ROOT}/Fabric/run
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
@IBAction func didPressCrash(_ sender: AnyObject) {
print("Crash button pressed!")
Crashlytics.sharedInstance().crash()
}
Firebase Remote Config allows you to remotely configure your active clients. FriendlyChat messages are restricted to a maximum length. While this length can be defined directly in the client, defining this maximum length with Firebase Remote Config allows an update to the maximum length to be applied to active clients.
In Firebase console, select the "Remote Config" panel and click "Add your first parameter". Set the parameter key to friendly_msg_length and the parameter value to 10. Select Publish Changes to apply the updates.
Confirm the pod 'Firebase/RemoteConfig'
dependency exists in your Podfile
file.
func configureRemoteConfig() {
remoteConfig = RemoteConfig.remoteConfig()
let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)
remoteConfig.configSettings = remoteConfigSettings
}
Create a fetch request for config and add a completion handler to pick up and use the config parameters.
func fetchConfig() {
var expirationDuration: TimeInterval = 3600
// If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from
// the server.
if self.remoteConfig.configSettings.isDeveloperModeEnabled {
expirationDuration = 0
}
remoteConfig.fetch(withExpirationDuration: expirationDuration) { [weak self] (status, error) in
if status == .success {
print("Config fetched!")
guard let strongSelf = self else { return }
strongSelf.remoteConfig.activateFetched()
let friendlyMsgLength = strongSelf.remoteConfig["friendly_msg_length"]
if friendlyMsgLength.source != .static {
strongSelf.msglength = friendlyMsgLength.numberValue!
print("Friendly msg length config: \(strongSelf.msglength)")
}
} else {
print("Config not fetched")
if let error = error {
print("Error \(error)")
}
}
}
}
Firebase A/B Testing helps you optimize your app experience by making it easy to run, analyze, and scale product and marketing experiments. Here you will use Firebase A/B testing to try different message lengths.
Click the Run button. Then search for the line with "Remote instance ID token" in the Xcode console. Make note of the token.
You have used Firebase to take Friendly Chat to the next level.