Push Notifications
Integrate your app with Referd push notifications and interactive in-app messaging.
Last updated
Inherit :UNUserNotificationCenterDelegate, MessagingDelegate
Add var gameballApp: Gameball?FirebaseApp.configure()
registerForPushNotifications() func registerForPushNotifications() {
UNUserNotificationCenter.current()
.requestAuthorization(options: [.alert, .sound, .badge]) {
[weak self] granted, error in
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
guard granted else { return }
self?.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
} func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
if let refreshedToken = InstanceID.instanceID().token() {
print("InstanceID token: (refreshedToken)")
self.gameballApp?.registerDevice(withToken: refreshedToken)
}
} func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
gameballApp?.notificationPopUP(notification: notification)
}