Push Notifications Guide
iOS Push Notifications Guide
iOS Push Notification Guide
StreamLayer SDK supports push notifications via the Apple Push Notification Service (APNs). StreamLayer uses push notifications to notify incoming chat messages and Watch Parties.
Prerequisites
To work with Push Notifications on the iOS platform, you will need to have a valid APNs certificate for your application and push notifications need to be enabled for your app. Configuring your project to work with Apple's back end service is beyond the scope of this document. Please check the latest Apple documentation for further details.
Integration with StreamLayer
The StreamLayer service needs your users APNs device token in order to send push Notifications to the device. If your user does not consent to Push Notifications, StreamLayer will not be able to send Push Notifications to their device.
To upload the device token to StreamLayer, use the function StreamLayer.uploadDeviceAPNsToken(deviceAPNsToken: token)to register your host app with the StreamLayer service. When a push notification is received, call StreamLayer.didReceiveRemoteNotification(user:userInfo) function to check if it needs to be processed by the StreamLayer SDK or if it is some other notification that your app needs to process.
Example Code
Here is an example that extends the AppDelegate for Push Notifications.
import UIKit
import UserNotifications
import StreamLayer
import RxSwift
/// SDK key can be created in the StreamLayer admin panel. Check the official documentation for the relevant link.
/// You MUST use your own key.
let sdkKey = "YOUR_SDK_HERE"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
fileprivate let window = UIWindow()
fileprivate var appCoordinator: AppCoordinator?
fileprivate let disposeBag = DisposeBag()
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication .LaunchOptionsKey: Any]?) -> Bool {
UITabBar.appearance().tintColor = .black
initiateStreamLayer()
let dependency = Dependency(authService: AuthService())
appCoordinator = AppCoordinator(window: window, dependency: dependency)
appCoordinator?.start().subscribe().disposed(by: disposeBag)
return true
}And then handle the notification when it comes in.
// Work with received notification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void {
// send notification's info to StreamLayer SDK
StreamLayer.didOpenReceivedNotification(center, userInfo: response.notification.request.content.userInfo)
completionHandler()
}Notification Settings
The StreamLayer SDK will create two notification channels in your app settings:
- StreamLayer
- StreamLayer Watch Party
You also have the option of customizing notification settings inside the StreamLayer SDK overlays.
User Receives a Notification
This screenshot below demonstrates what an IOS Notification looks like when one is sent to a user.

Updated 6 months ago
