Handling push notifications

Usage guides to help you get started with the Push Notifications in the iOS Knock SDK.

Note: We Recommend taking advantage of our KnockAppDelegate to make managing your Push Notifications simpler.

Prerequisites

Before proceeding, ensure you've configured push notifications within your Knock account. For guidance on this initial setup, refer to our Push Notification Configuration Guide.

Step 1: Enabling Push Notifications in Your App

  1. Configure APNs in Your App:
    • Open your project in Xcode.
    • Navigate to your app target's Signing & Capabilities tab.
    • Click the "+" capability button and add Push Notifications to enable Apple Push Notification service (APNs).
  2. Enable Background Modes:
    • Still in the Signing & Capabilities tab, add the Background Modes capability.
    • Check Remote notifications to allow your app to receive silent push notifications.

Step 2: Registering for Push Notifications

Implement the following in your AppDelegate or SceneDelegate to register for push notifications:

KnockAppDelegate:

If using the KnockAppDelegate, this will be handled for you automatically.

Manually:

Step 3: Updating the Message Status of a Push Notification.

If a push notification is sent via Knock, it will contain a knock_message_id property that includes the corresponding message Id. This can then be used to update the message status.

KnockAppDelegate:

If using the KnockAppDelegate, this will be handled for you automatically.

Manually:

Step 4: Configuring Silent Push Notifications

Silent push notifications allow your app to update content in the background without alerting the user. Ensure that your Knock APNS message template has silent notifications enabled.

Message Template Settings

KnockAppDelegate:

Manually: