Add the iOS Notification Service Framework to your project

The AcousticMobilePushNotification.xcframework enables support for media attachments (images, audio, and video) and also enables support for Acoustic dynamic action categories. This second framework integration requires independent/additional app provisioning with support for push notifications.

A notification extension functions as a second app within your overall app bundle. You must generate provisioning for the notification extension. A typical pattern for the bundle ID is com.company.app.notification if your app bundle ID is com.company.app.

Add the target

  1. In your Xcode project, go to the File menu and select New > Target. A dialog box opens.

  2. In the dialog box, select iOS at the top and Notification Service Extension in the center of the window.

  3. Name the target, and click Finish.

  4. Click Activate on the confirmation modal to accept the new entitlement Xcode adds to the project.

  5. The new target is added to the Xcode project.

Add the framework 

  1. Add the framework to the notification service target.

    1. Select your project in the Project Navigator.

    2. Select your Notification Service  target.

    3. Go to the General tab.

    4. In the  Frameworks and Libraries section, Click the + button and add the AcousticMobilePushNotification.xcframework.

  2. Add -ObjC to the Other Linker Flags build options for the Notification Service.

  3. Add App Group capability to your notification service extension target.

    1. Go to the Signing & Capabilities tab.

    2. Click the + button to add a new capability.

    3. Once the App Group is added, you should see it listed under the App Groups section.

    4. Check the checkmark for the App Group. Be sure to use the same app group as the main application.

  4. Add the Keychain Sharing capability to your notification service extension target. Be sure to use the same value as the main application.

    1. From the Signing & Capabilities tab.

    2. Click the + button to add a new capability.

    3. Select Keychain Sharing from the list.

    4. Add a Keychain Group value to the list. Be sure to use the same value as the main application.

To add media attachments to notifications, you must configure the mutable-content flag and media-attachment key in the iOS 10 payload. For more information, refer to the following articles:

Implement the framework automatically

In the NotificationService.h file, replace the contents with the following.

#import <UserNotifications/UserNotifications.h> #import <AcousticMobilePushNotification/AcousticMobilePushNotification.h> @interface NotificationService : MCENotificationService @end

Swift
In the NotificationService file, replace the contents with the following.

import UserNotifications import AcousticMobilePushNotification class NotificationService: MCENotificationService { }

Implement the framework manually

  1. In the NotificationService.h file, replace the contents with the following.

    #if __has_feature(modules) @import UserNotifications; @import AcousticMobilePushNotification; #else #import <UserNotifications/UserNotifications.h> #import <AcousticMobilePushNotification/AcousticMobilePushNotification.h> #endif @interface NotificationService : UNNotificationServiceExtension @property MCENotificationService * notificationService; @end
  2. In the NotificationService.m file, replace the contents with the following.

    #import "NotificationService.h" #import "MCEManualConfiguration.h" @interface NotificationService () @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; @end @implementation NotificationService -(instancetype)init { if(self = [super init]) { // If using a dictionary based configuration: [MCEConfig sharedInstanceWithDictionary: MCEManualConfiguration.xmlSettings]; // If using the MceConfig.json file, you only need to initialize the object self.notificationService = [[MCENotificationService alloc] init]; } return self; } - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { if(request.content.userInfo[@"notification-action"]) { [self.notificationService didReceiveNotificationRequest: request withContentHandler: contentHandler]; return; } } - (void)serviceExtensionTimeWillExpire { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. [self.notificationService serviceExtensionTimeWillExpire]; } @end

Swift
In the NotificationService file, replace the contents with the following.

import UserNotifications import AcousticMobilePushNotification class NotificationService: UNNotificationServiceExtension { let mobilePushNotificationService: MCENotificationService override init() { // If using a dictionary based configuration: // MCEConfig.sharedInstance(with: Config.mobilePushConfig) // If using the MceConfig.json file, you only need to initialize the object mobilePushNotificationService = MCENotificationService() super.init() } override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { if request.content.userInfo["notification-action"] != nil { mobilePushNotificationService.didReceive(request, withContentHandler: contentHandler) return } // Handle other notifications here } override func serviceExtensionTimeWillExpire() { mobilePushNotificationService.serviceExtensionTimeWillExpire() } }

📘

Note:

If you are using the MCEConfig.json for configuration you can remove the dictionary based configuration in the init method.

Add the MceConfig.json file to the Notification Service target. Open the MceConfig.json file and check the notification service target membership in the Target Membership of the File Inspector in the Xcode pane.