Displaying an image preview

👍

Expected result of the “Displaying an image preview” step:

The push notification is displayed with a small square image on the right.

You can use this guide to verify that push notifications with images are being sent correctly.

1. Creating the Extension

  1. In Xcode, select File > New > Target.
  2. Choose Notification Service Extension and click Next.
  3. Enter MindboxNotificationServiceExtension as the product name, then click Finish.
  4. In the Activate scheme dialog, click Activate.

2. Extension Setup

2.1 iOS Deployment Target

Make sure the iOS Deployment Target versions match for the following targets:

  1. Main target
  2. Service Extension
  3. Content Extension

You can find this setting here: Your Project Name → Targets → Target Name → General → Minimum Deployments → iOS

❗️

The iOS Deployment Target is critical for proper operation of the Service Extension and Content Extension.

Make sure to double-check this setting, especially after upgrading to a new Xcode version.
iOS Deployment Target may update automatically after that, which can cause the Service Extension and Content Extension to stop working correctly.

2.2 App Groups

  1. Open the project settings.

  2. Select the MindboxNotificationServiceExtension target.

  3. Go to the Signing & Capabilities tab.

  4. Click + Capability and select App Groups.

  5. Add a new group using the following format: group.cloud.Mindbox.{app bundle ID}

    For example, if the app bundle ID is Maestra-Sample-App, the App Group value should be:
    group.cloud.Mindbox.Maestra-Sample-App

❗️

Configuring an App Group is mandatory for the Mindbox SDK.

Skipping this step may cause the extension to crash when handling push notifications, making the issue hard to debug.

2.3 Extension Signing

The extension must be signed with the same certificate as the main app. If you’re using automatic signing, Xcode will handle this for you. If you’re using manual signing, make sure to create the required certificates for the extension target and configure them in Signing & Capabilities.

2.4. Verifying Rich Push Notifications Using Xcode Debug Builds

In Xcode, go to Target → Build Phases → Embed App Extensions and make sure the Copy only when installing checkbox is unchecked.

❗️

Uncheck this option ONLY if you plan to test Rich Push Notifications using debug builds created directly in Xcode.

3. Adding the SDK to the project

  1. In Xcode, click File → Add Packages in the top menu.
  2. In the dialog that opens, add the Mindbox SDK repository URL https://github.com/mindbox-cloud/ios-sdk and click Add Package.
  3. After the package is downloaded, assign the targets:
  • Add MindboxNotificationsService to the previously created MindboxNotificationServiceExtension
  • Add MindboxNotificationsContent to the previously created MindboxNotificationContentExtension

4. Configuring the SDK in the App

In the extension’s main file, configure the following:

  • Import the MindboxNotifications library;
  • Initialize MindboxNotificationService();
  • Add calls to didReceive and serviceExtensionTimeWillExpire in two places.

import UserNotifications
import MindboxNotifications

class NotificationService: UNNotificationServiceExtension {

  lazy var mindboxService: MindboxNotificationServiceProtocol = MindboxNotificationService()

  override func didReceive(_ request: UNNotificationRequest,
                           withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    mindboxService.didReceive(request, withContentHandler: contentHandler)
  }

  override func serviceExtensionTimeWillExpire() {
    mindboxService.serviceExtensionTimeWillExpire()
  } 
}

👍

Verify the result of the “Displaying an image preview” step:

The push notification is displayed with a small square image on the right.

Make sure the push notification with an image is sent correctly.