Stay connected with your customers by utilizing push notifications to alert them of new chat messages, release notes, and news articles. This will deepen engagement and foster stronger relationships.Gleap supports Firebase Cloud Messaging to send push notifications to users.
To make use of Gleap Push Notifications you must add the Firebase Cloud Messaging service to your app or website. Learn how to get started with FCM here.
Open your project in Firebase and open the project settings.Click on “Cloud Messaging” and, if it is not already enabled, activate the Firebase Cloud Messaging API (V1).Proceed to the “Service Accounts” section and generate a new private key, which will automatically create a file named like serviceAccountKey.json.Next, open the project settings in Gleap, select “Push Notifications”, and upload the serviceAccountKey.json file. Finally, save your configuration.
The last step to complete the push notification setup is to subscribe to the user topic, which Gleap will send the push notifications to. In order to do so, you will need to register the register & unregister push message topic callbacks.
Copy
import Foundationimport UIKit// Don't forget the importsimport Gleapimport Firebaseimport FirebaseMessaging// Add the GleapDelegate protocol to your view controllerclass DemoViewController: UIViewController, GleapDelegate { override func viewDidLoad() { // Assign self to the delegate Gleap.sharedInstance().delegate = self; } func registerPushMessageGroup(_ pushMessageGroup: String) { // Register topic Messaging.messaging().subscribe(toTopic: pushMessageGroup) { error in } } func unregisterPushMessageGroup(_ pushMessageGroup: String) { // Unregister topic Messaging.messaging().unsubscribe(fromTopic: pushMessageGroup) { error in } }}
In order to open the message, the user clicked on, you will need to add some extra code to your app. The idea is to get the data from the push notification and then pass it to the SDK by utilizing handlePushNotification().Please note depending on your specific code, the callbacks might be different. The important part is to forward the notification data to Gleap.handlePushNotification().
Copy
import UIKitimport Foundationimport Gleap@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate { @available(iOS 10.0, *) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo print("Handle push from background or closed \(userInfo)") // Check for specific notification indicating it's from "GLEAP" if let sender = userInfo["sender"] as? String, sender == "GLEAP" { Gleap.handlePushNotification(userInfo) } completionHandler() } // Add other necessary AppDelegate methods...}