Push Notifications
The Channelize.io iOS SDK allows your users to receive important messages when the app is running in the background or a device is idle. You can also build your own Push Notifications system using Channelize.io webhooks.
Do the following steps to setup push notifications:
Step 1: Create a firebase account and use its messaging framework. Add the following pods.
pod 'Firebase/Messaging'
pod 'Firebase/Core'
Step 2: In AppDelegate.swift
file in didFinishLaunchingWithOptions
functions call this.
FirebaseApp.configure()
Messaging.messaging().delegate = self
Step 3: Write MessagingDelegate
functions and update fcmToken using Channelize.updateToken(token: fcmToken)
.
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("FCM Token -> \(fcmToken)")
Channelize.updateFcmToken(token: fcmToken, completion: {(status,errorString) in
if status {
print("FCM Token Registered Successfullt")
} else {
print("Failed to Register FCM Token with errorString\(errorString ?? "")")
}
})
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Message Recieved \(remoteMessage.appData)")
}
}
Step 4: Differentiate your main app push notifications (if Channelize.io real-time messaging is used as an integration) and Channelize.io notifications as shown below.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if userInfo["isMessenger"] != nil{
openPrimeMessenger(contentInfo: userInfo)
}else{
// Handle yours app notifications
}
}
func openPrimeMessenger(contentInfo: [AnyHashable : Any]) {
if let navigationController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController{
ChUI.launchChannelize(navigationController: navigationController, data: contentInfo)
}
}
Register/Update FCM Token
To register and update the FCM token make the below API call.
Channelize.updateFcmToken(token: fcmToken, completion: {(status,errorString) in
if status {
print("FCM Token Registered Successfullt")
} else {
print("Failed to Register FCM Token with errorString\(errorString ?? "")")
}
})
Delete FCM Token
To delete the FCM token for a user make the below API call.
Channelize.deleteToken()