Push Notifications (v5)

How to manage and receive push notifications with the Apps Panel iOS SDK

The Apps Panel iOS SDK provides a push module, letting you target users and send scheduled push notifications.

Integration

If you want to use push notifications in your app with the Apps Panel SDK, you need to add the following code to your AppDelegate :

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        /* ... */
        
        UNUserNotificationCenter.current().delegate = self

        return true
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Add this line if you want to remove the app badge when opening the app
        application.applicationIconBadgeNumber = 0
    }

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

}

extension AppDelegate: UNUserNotificationCenterDelegate {

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
    {
        PushNotificationManager.shared.manageNotification(
            notification,
            show: true,
            state: UIApplication.shared.applicationState,
            completionHandler: completionHandler
        )
    }

}

Asking for permission

In your back-office, you can set, in the SDK's configuration, if you want an automatic permission prompt at app launch. If you set it to manual, you must call PushNotificationManager.shared.registerForPushNotifications(application: application) where you want the push notification's permission prompt to be displayed.


What’s Next