Blueshift Service Extension Configuration

For handling media based push notifications apple provide two notifications extensions, Service extension since iOS 10 onward.
See notification extensions integration here

If analytics want to capture push notification delivery event precisely, it's necessary to add Service extension and Blueshift integration in it.

Things needed to take care
* Operating system must be iOS 10 +
* Notification service extension integrated along with the app and SDK method called inside in it.

 

Set up Notification Service Extension

  1. In Xcode 8 and above File -> New -> Target
  2. Select Notification Service Extension, press Next
  3. Fill in the details in the pop-up and press Finish.(The pop-up asks you to add new schema, do it)
  4. It will create a new group with the name you give. You can see this in directory panel in x code.
  5. Select the newly created target from the project target list
  6. You need to configure a new bundle id and provisioning profiles for app extension in Apple developer portal.
  7. Fill in the details in General Tab inside app extension target.
  8. Expand newly created group in left panel, it may contain NotificationService.h, NotificationService.m and Info.plist files
  9. Open Info.plist file and add Application Transport Security

For example, you can add a specific domain like:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
      <key>yourserver.com</key>
      <dict>
         <!--Include to allow subdomains-->
         <key>NSIncludesSubdomains</key>
         <true/>
         <!--Include to allow HTTP requests-->
         <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
         <true/>
         <!--Include to specify minimum TLS version-->
         <key>NSTemporaryExceptionMinimumTLSVersion</key>
         <string>TLSv1.1</string>
     </dict>
   </dict>
</dict>

The lazy option is:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Next step is need to install BlueShift-iOS-SDK pod app extension for notification service extension

target 'APP EXTENSION TARGET NAME' do
  pod 'BlueShift-iOS-Extension-SDK'
end

 

Objective C

  1. open NotificationSevice.h and import header

    #import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>
  2. Call this method for downloading and showing attachment in push notifications.
    - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    
       self.contentHandler = contentHandler;
       self.bestAttemptContent = [request.content mutableCopy];
       //Modify the notification content here...
       [[BlueShiftPushNotification sharedInstance] setApiKey: @"yourApiKeyHere"];
       self.bestAttemptContent.attachments = [[BlueShiftPushNotification sharedInstance] integratePushNotificationWithMediaAttachementsForRequest:request];
       self.contentHandler(self.bestAttemptContent);
    }
    - (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.bestAttemptContent.attachments = [BlueShiftPushNotification sharedInstance].attachments;
       self.contentHandler(self.bestAttemptContent);
    } 

Swift

  1. Create bridge-header file for notification service extension and import
    #import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>
  2. Open NotificationService.swift , call this method for downloading and showing attachment in push notification
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        BlueShiftPushNotification.sharedInstance().apiKey = "yourApiKeyHere"
        if let bestAttemptContent = bestAttemptContent {
            // Modify the notification content here...
            bestAttemptContent.attachments = BlueShiftPushNotification.sharedInstance().integratePushNotificationWithMediaAttachements(for: request) as! [UNNotificationAttachment]
    
            contentHandler(bestAttemptContent)
        }
     }
    
    
     override func 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.
        bestAttemptContent?.attachments = BlueShiftPushNotification.sharedInstance().attachments
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
     }


* Every push notification payload must contain mutable-content flag with value '1' (for invoking extension)

Was this article helpful?
0 out of 0 found this helpful