Add the iOS Notification service framework to your Cordova project

The AcousticMobilePushNotification.xcframework enables support for media attachments in notifications for iOS applications. When a user on an iOS device receives a notification with a media attachment from the APNS service, the incoming notification is processed before it is displayed to the user. First, the URL for the media attachment is extracted, and then the media file is downloaded and attached to the notification.

A notification extension essentially 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.

  1. Add a new Target to your Xcode project. 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 the Notification Service Extension for the Application Extension.
  3. Click Next and a new dialog box opens:
    a. Add the Product Name for your new target. For this example, NotificationService.
    b. Choose a language. For example, Objective C.
    c. Select your project and the application in which you would like to embed the new target.
    d. Click Finish to add your new target.
  4. A new dialog appears, prompting you to activate a new scheme for the Notification Service target. Click Activate. The following are added to your project:
    • A new folder on your project navigator with the Notification Service code.
    • A new Notification ServiceTarget on your main project.
  5. Check if the following items are complete:
    • The AcousticMobilePushNotification.xcframework is on the project with the Embed and sign option selected.
    • The minimum deployment target from your Notification Service Target matches its parent project.
    • In Build Settings, check the Other Linker Flags property is set to -ObjC on your Notification Service target.
  6. Add the following to your Notification Service Target’s Frameworks and libraries in the General tab.
    • AcousticMobilePushNotification.xcframework
    • libCordova.a
  7. In Signing & Capabilities, add the following two new capabilities to your Notification Service Target:
    a. Add the App Group capability to your notification service extension target. Be sure to use the same app group as the main application.
    b. Add the Keychain Sharing capability to your notification service extension target. Be sure to use the same value as the main application.
  8. Select the following files from the main application and add your new Notification Service Target to their Target Membership.
    • Config.xml
    • MCEManualConfiguration.m
  9. Since the main project is configured manually using the Config.xml file, you will have to configure your new Notification Service Extension manually. Apply the following changes to your Notification Service files:
    .h file:
    a. Import the AcousticMobilePushNotification framework:
#import <AcousticMobilePushNotification/AcousticMobilePushNotification.h>

b. Add a mce notification service property.

@property MCENotificationService * notificationService;

.m file
a. Import MCEManualConfiguratio.h.

#import "MCEManualConfiguration.h"

b. Create an initializer method to initialize your MCENotificationService property:

-(instancetype)init {
    if(self = [super init]) {
        [MCEConfig sharedInstanceWithDictionary:
MCEManualConfiguration.xmlSettings];
        self.notificationService =
[[MCENotificationService alloc] init];
    }
    return self;
}

c. Update the didReceiveNotificationRequest method to use the notification-action.

if(request.content.userInfo[@"notification-action"])
{
  [self.notificationService
didReceiveNotificationRequest: request
withContentHandler: contentHandler];
  return;
}

d. Finally, in the serviceExtensionTimeWillExpire method, call the mce mobile push method of the same name:

[self.notificationService
serviceExtensionTimeWillExpire];

Example NotificationService.h file

#import <UserNotifications/UserNotifications.h>
#import <AcousticMobilePushNotification/AcousticMobilePushNotification.
h>
@interface NotificationService : UNNotificationServiceExtension
@property MCENotificationService * notificationService;
@end

Example NotificationService.m file

#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]) {
        [MCEConfig sharedInstanceWithDictionary: MCEManualConfiguration.
xmlSettings];
        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 {
    [self.notificationService serviceExtensionTimeWillExpire];
}

@end