Castled provides a convenient way to send push notifications to your applications directly from our dashboard. Follow these steps to send your first push notification to your application:

Prerequisite

To enable push notifications on your iOS application using the Castled dashboard, you are required to upload the APNS Authentication Key obtained from your Apple Developer account.

Refer here for more information on how to obtain .p8 file.

Configuring App Target for Push Notification

To enable push notifications for your iOS app, you need to configure the app’s target settings in Xcode. This involves enabling the push notifications capability, enabling remote notifications, and adding an App Group ID.

Follow the steps below to set up these features in the Signing & Capabilities tab of your app target:

1. Enabling Push Notifications Capability

To receive push notifications, you must explicitly enable this capability.To enable push notification :

  1. Open your project in Xcode and select the app target.
  2. Go to the Signing & Capabilities tab.
  3. Click on the ”+ Capability” button to add a new capability.
  4. Search for “Push Notifications” and add it.

2. Enabling Remote Notifications

Remote notifications are essential for receiving notifications from a server.This will allow your app to be awakened in the background to receive notifications.

To enable Remote notifications :

  1. Within the Signing & Capabilities tab, ensure that the Background Modes capability is present.
  2. If not, add it by clicking the ”+ Capability” button and selecting “Background Modes.”
  3. In the Background Modes section, find and check the “Remote notifications” option.

It is advised to enabling Remote Notifications for efficient Uninstall tracking and Delivery Status tracking even in cases where app is in the background, not running or inactive.

3. Adding an App Group ID

App Groups facilitate the sharing of data between multiple apps developed by the same organization and their extensions. While this is not required specifically for push notifications, it is relevant if you have any notification-related extensions for rich notifications or need to manage a shared container of data.

To add an App Group:

  1. Still on the Signing & Capabilities tab, click the ”+ Capability” button to add a new capability.
  2. Type “App Groups” in the search bar and select it from the list.
  3. Under the App Groups section, click the ”+” to create a new group.
  4. Enter the App Group ID using the format group.your_bundle_id.castled.
  5. Make sure the App Group ID is checked to enable it.

To ensure proper integration, we recommend setting up a separate App Group ID specifically for Castled.The format should be group.your_bundle_id.castled. Make sure to enable this same App Group ID for all targets where Castled is utilized.

Registering Push Notification

In iOS 10 and above, to handle push notifications, you need to implement the following method from UIApplicationDelegate protocol and add the three steps mentioned in the code snippet below for registering push notification.

application(_:didFinishLaunchingWithOptions:)

This method is called when the app finishes launching. You can use this method to register for remote notifications and configure the notification settings.

Make sure the appGroupId mentioned above is the same as the App Group ID configured in the Signing & Capabilities tab of the targets. The App Group ID should be enabled for all targets where Castled is utilized, especially if you are using extensions.

If you haven’t enabled App Groups, there is no need to set appGroupId.

Requesting User Permission for Push Notifications

Obtaining user authorization is a crucial requirement for sending push notifications to an iOS application. When your app requests authorization for the first time, the system presents a prompt to the user, giving them the choice to grant or deny the request. The user’s response is then recorded by the system for future reference.

AppDelegate Swizzling in Castled SDK

Castled SDK is designed to simplify push notification handling. By default, swizzling is enabled, which means the SDK automatically handles the registration of device tokens, the presentation of notifications, and the response to user interactions with those notifications.

For details on utilizing callback methods after swizzling, which enable developers to implement custom behaviors or logic following the Castled SDK’s default notification lifecycle handling, refer to this section

Disabling AppDelegate Swizzling

To disable method swizzling with Castled SDK, you must update the Info.plist file of your application. Add a new key-value pair where the key is specific to the Castled SDK’s configuration and the value explicitly indicates that swizzling should be turned off.

Refer to this section for instructions on how to disable swizzling in the Castled SDK, as well as how to manually handle push notifications afterwards.

Custom handling of User Actions

The Castled SDK provides support for handling custom notification actions when the user interacts with push notifications in your application. By implementing the CastledNotificationDelegate protocol in your AppDelegate class, you can define the behavior for different notification actions such as deeplinking, navigating to a specific screen, or displaying a rich landing page.

CastledNotificationDelegate method

notificationClicked This delegate method is invoked when a user clicks on a notification that was displayed as a result of a push notification sent from the Castled SDK. It provides detailed context about the notification that was clicked, allowing the application to handle different actions appropriately.

Parameters:

type : A CastledNotificationType indicating the type of notification. The values include ‘push’, ‘inapp’, ‘inbox’.

CastledButtonAction : An optional type providing additional information associated with the notification, such as a URL to open or title to display,click action type etc…

buttonAction.actionType : A CastledClickActionType representing the action taken by the user. The values include:

  • deepLink
  • navigateToScreen
  • richLanding
  • requestForPush
  • dismiss
  • custom

userInfo : A dictionary containing the original notification payload. This includes the custom data that was sent with the notification for the application to use.

Configuring Notification Categories and Actions

Apps are required to enable support for actionable notifications. During app launch, it is necessary to register one or more notification categories that define the types of notifications your app sends. Each category is associated with specific actions that users can take when receiving a notification of that type.

While each category can have up to four actions, the actual number of displayed actions may vary depending on the notification display. For instance, banners typically show a maximum of two actions.

Registering the Notification Categories for Your App

By passing the notificationCategories parameter, you can define a set of categories and associated actions for your notifications. Each category corresponds to a type of notification that your app can receive, and for each category, you can specify the actions that a user can take directly from the notification.

This flexibility allows app developers to create a rich and interactive notification experience, tailored to the needs of their application and its users.


The UNNotificationActionOptions.foreground in swift and UNNotificationActionOptionForeground in Objective C option is used to specify the behavior of a notification action when it is clicked by the user. Make sure this option is included, so that the action launches the application and bring it to the foreground.

FAQ