Media Push

Step 1: Create a New Notification Service Extension

To create a new Notification Service Extension to your application:

  1. On Xcode click File > New > Target. Choose Notification Service Extension

  2. Choose Notification Service Extension

  3. A new class named NotificationService will be created. It should be extended from MyNetmeraNotificationServiceExtension class.

Your NotificationService class should look like the following:

import UserNotifications
import NetmeraNotificationServiceExtension

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

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

Optional: Integrating Notification Service Extension Using CocoaPods

If you're using a Podfile for dependency management, follow these steps along with the rest of the steps from 1 to 5:

  • Add NetmeraNotificationServiceExtension in your Podfile:

  • Install it to your extension target.

pod 'NetmeraNotificationServiceExtension'

Note: If you're not using CocoaPods, you can skip this step.

Step 2: Add Your AppGroupName

  1. Add your AppGroupName in your Netmera-Config.plist.

<key>sdk_params</key>
<dict>
    <key>app_group_name</key> // Add this line in Config.plist
    <string>{YourAppGroupName}</string> // Add this line in Config.plist
    <key>use_ui_scene</key>
    <false/>
    <key>api_key</key>
    <string>{API_KEY}</string>
    <key>custom_events</key>
    <array>
        <string>{YourCustomEvent}</string>
    </array>
</dict>

Step 3: Select Targets in Target Membership

  1. Select all three targets in the Target Membership section on the right.

Step 4: Select Main Project & Service Extension

  1. Go to Notification Service > Target Membership.

  2. Select both the main project and the service extension.

Step 5: Receiving Http Media Contents

Sample Service Extention Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>NSExtension</key>
    <dict>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.usernotifications.service</string>
        <key>NSExtensionPrincipalClass</key>
        <string>$(PRODUCT_MODULE_NAME).NotificationService</string>
    </dict>
</dict>
</plist>

If you want to allow your application to receive http media contents:

  1. Click Info.plist under Notification Service Extension,

  2. Add App Transport Security Settings,

  3. Add Allow Arbitrary Loads under App Transport Security Settings and set it to YES.

Troubleshooting

If push notifications do not display correctly:

  1. Go to Build Settings > Runpath Search Paths in the extension target. Ensure the following paths are added:

@executable_path/../../Frameworks  
@executable_path/Frameworks  
@loader_path/Frameworks
  1. Remove the default label in MainInterface.

Last updated

Was this helpful?