Push Notifications
Integrate your app with Gameball push notifications and interactive in-app messaging.
Gameball uses Firebase to deliver maximum experience in your app. This includes push notifications, interactive in-app messaging and referrals support.

Configure Gameball With Your Firebase

Before you start, you must configure your Firebase on your Gameball account. Follow the steps in Configure your Firebase account on Gameball for mobile push notifications article from our Help Center related to push notifications.

Handling Push Notifications Integration

Configure notifications as usual and add two more methods using our SDK. This is normal integration for general firebase notifications configuration, so here is a how-to guide.
1. Add the below to the AppDelegate class
1
Inherit :UNUserNotificationCenterDelegate, MessagingDelegate
2
Add var gameballApp: GameballApp?
Copied!
2. Then put these lines didFinishLaunchingWithOptions() in AppDelegate
1
FirebaseApp.configure()
2
registerForPushNotifications()
Copied!
3. Add these stack of lines to the AppDelegate class
1
func registerForPushNotifications() {
2
UNUserNotificationCenter.current()
3
.requestAuthorization(options: [.alert, .sound, .badge]) {
4
[weak self] granted, error in
5
UNUserNotificationCenter.current().delegate = self
6
Messaging.messaging().delegate = self
7
guard granted else { return }
8
self?.getNotificationSettings()
9
}
10
}
11
12
func getNotificationSettings() {
13
UNUserNotificationCenter.current().getNotificationSettings { settings in
14
guard settings.authorizationStatus == .authorized else { return }
15
DispatchQueue.main.async {
16
UIApplication.shared.registerForRemoteNotifications()
17
}
18
}
19
}
Copied!
4. Here we need to add this method to register token to Gameball in this method
1
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
2
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
3
let token = tokenParts.joined()
4
if let refreshedToken = InstanceID.instanceID().token() {
5
print("InstanceID token: (refreshedToken)")
6
self.gameballApp?.registerDevice(withToken: refreshedToken)
7
}
8
}
Copied!
5. Here we need to add this method to let Gameball handle everything related to Gameball Widget
1
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
2
gameballApp?.notificationPopUP(notification: notification)
3
}
Copied!
Your users can now receive push notifications from Gameball.
Last modified 2mo ago