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
-
In your Xcode project, go to the File menu and select New > Target. A dialog box opens.
-
In the dialog box, select iOS at the top and Notification Service Extension in the center of the window.
-
Name the target, and click Finish.
-
Click Activate on the confirmation modal to accept the new entitlement Xcode adds to the project.
-
The new target is added to the Xcode project.
Add the framework
-
Add the framework to the notification service target.
-
Select your project in the Project Navigator.
-
Select your Notification Service target.
-
Go to the General tab.
-
In the Frameworks and Libraries section, Click the + button and add the
AcousticMobilePushNotification.xcframework
.
-
-
Add
-ObjC
to the Other Linker Flags build options for the Notification Service. -
Add App Group capability to your notification service extension target.
-
Go to the Signing & Capabilities tab.
-
Click the + button to add a new capability.
-
Once the App Group is added, you should see it listed under the App Groups section.
-
Check the checkmark for the App Group. Be sure to use the same app group as the main application.
-
-
Add the Keychain Sharing capability to your notification service extension target. Be sure to use the same value as the main application.
-
From the Signing & Capabilities tab.
-
Click the + button to add a new capability.
-
Select Keychain Sharing from the list.
-
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
-
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 -
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.
Updated 5 months ago