Setting up Badges for Cordova

This guide describes the process of implementing Badges for Pushwoosh Cordova plugin

Since the Cordova plugin does not contain the PWNotificationExtensionManager header, you have to perform several additional steps to implement Badges for your Cordova project.

That's what you need for setting Badges up:

To implement badges for iOS Native app, please refer to the Setting up Badges guide..

1. Add Notification Service Extension (File -> New -> Target...)

2. Select the "Notification Service Extension"

3. Add Pushwoosh.xcframework to NotificationService extension target as follows:

  1. Choose NotificationService extension target.

  2. Go to the "General" tab.

  3. Find 'Framework and Libraries' and press '+' button.

  4. Select Pushwoosh.xcframework.

4. Update the Notification Service Extension code as follows:

#import "NotificationService.h"
#import "PWNotificationExtensionManager.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    [[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler];
}

- (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.contentHandler(self.bestAttemptContent);
}

@end

5. Add the "App Groups Capability" for each target of your application

6. Add the App Groups ID to your info.plist for each target of your application

<key>PW_APP_GROUPS_NAME</key>
<string>group.com.example.demoapp_example</string>

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.

Last updated