1. Home
  2. SDK iOS
  3. Advanced
  4. Push Notifications

Push Notifications

BEAR frontend provides feature to manage application notification. This section explains how to enable this feature in BearSDK.

For the notifications to work with BearSDK, you must provide to BEAR your Apple Push Services certificate (*.pem file).

Finally you need to call BearSDK.shared.registerDevice(withDeviceToken token: Data) with the APN token. The APN token can be retrieved in the UIApplicationDelegate.didRegisterForRemoteNotificationsWithDeviceToken method:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    BearSDK.shared.registerDevice(withDeviceToken: deviceToken)
}

To request APN token you have to execute:

if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert , .sound]) { (granted, error) in
        guard granted else { return }
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
        }
    }
} else {
    let settings = UIUserNotificationSettings(types: [.alert, .sound, .badge], categories: nil)
    UIApplication.shared.registerUserNotificationSettings(settings);
    UIApplication.shared.registerForRemoteNotifications();
}

This way the Apple Push Notifications token will be linked to the device id assigned at BEAR backend. You can retrieve this device id in your application by calling BearSDK.shared.deviceId method.

Was this article helpful to you? Yes No

How can we help?