Push
Set up push notifications.
APNS certificate
To use push notifications with this SDK, you have to provide APNS Key and upload it to our Sinch Panel.
Xcode Capabilities
Make sure you’ve enabled the Remove notifications
capability in Background Modes
in your target configuration in the tab Signing & Capabilities
and the Push Notifications
tab.
Methods in AppDelegate.swift or AppDelegate.m:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
SinchChatSDK.shared.push.sendDeviceToken(deviceToken)
}
Make sure you’ve added UNUserNotificationCenterDelegate
to AppDelegate definition or to you own class.
swiftswift
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if SinchChatSDK.shared.push.handleNotificationResponse(response) {
// this is our notification and it is handled by SinchChatSDK
}
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if let presentationOptions = SinchChatSDK.shared.push.handleWillPresentNotification(notification) {
completionHandler(presentationOptions)
return
}
completionHandler([])
}