Blueshift Content Extension Configuration

iOS 10 has introduced customised push notification too by Notification content extension (app extension).
A developer needs to add an extension like we did for the Notification service extension for configuring carousel push notification, SDK support animated and non-animated push notification with carousel themes, carousel type and theme can be set inside push notification payload.

 

 Set up Notification Content Extension

  1. In Xcode 8 and above File -> New -> Target
  2. Select Notification Content 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 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 NotificationViewController.h, NotificationViewController.m, MainInterface.storyboard 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>

add NSExtensionAttributes inside NSExtension

UNNotificationExtensionCategory with array items carousel_animation and carousel

UNNotificationExtensionInitialContentSizeRatio with value 0.7

a sample one below

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>UNNotificationExtensionCategory</key>
        <array>
            <string>carousel_animation</string>
            <string>carousel</string>
        </array>
        <key>UNNotificationExtensionDefaultContentHidden</key>
        <false/>
        <key>UNNotificationExtensionInitialContentSizeRatio</key>
        <real>0.7</real>
    </dict>
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.usernotifications.content-extension</string>
</dict>

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

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

Open MainInterface.storyboard and remove 'Hello World' UILabel
Open NotificationViewController.h and import header

#import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>
- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion {
    [self setCarouselActionsForResponse:response completionHandler:^(UNNotificationContentExtensionResponseOption option) {
    completion(option);
    }];
}

The file looks like

@implementation NotificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any required interface initialization here.
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)didReceiveNotification:(UNNotification *)notification {
    [self showCarouselForNotfication:notification];
}

- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion {
    [self setCarouselActionsForResponse:response completionHandler:^(UNNotificationContentExtensionResponseOption option) {
    completion(option);
    }];
}

@end
 
Swift

Create bridge-header file for notification content extension and import

`#import <BlueShift-iOS-Extension-SDK/BlueShiftAppExtension.h>`
class NotificationViewController: BlueShiftCarousalViewController, UNNotificationContentExtension {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any required interface initialization here.
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
}

func didReceive(_ notification: UNNotification) {
    showCarousel(forNotfication: notification)
}

func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
    setCarouselActionsFor(response) { (option) in
        completion(option)
    }
}

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