WEContentExtension 1.0.0

WEContentExtension 1.0.0

Maintained by WEPersonalization.



WEContentExtension

Version License Platform LastUpdated

WEContentExtension

WEContentExtension is extension SDK on WebEngage to support Rich push layouts inside iOS Applications

Table of Content

Click to Expand

Prerequisites

  • WebEngage SDK needs to be integrated inside project
  • Basic knowledge of Service Extension and Content Extension
  • Basic knowledge about push notification , swift / Objc Programing Langage

  • Step 1 : Create content extension for Project

    This guide provides step-by-step instructions for integrating a content extension into your iOS project. Content extensions allow you to extend the functionality of your app by providing additional content that can be displayed in various contexts, such as the Today view or Messages app.

    • Open your Xcode project.

    • From the menu, select File > New > Target....

    • Choose App Extension from the list of templates.

    • Select the type of extension you want to create (e.g., ContentExtension).

    • Provide a name for your extension and click Finish.

    • Screenshots

      Screenshot 1

      Screenshot 1

      Screenshot 2

      Screenshot 2

      Screenshot 3

      Screenshot 3

      Screenshot 4

      Screenshot 4

  • Step 2 : Integrate WebEngage inside ContentExtension

    There are 2 common methods for integrating a library inside a Content Extension:

    Note: Choose Either SPM or CocoaPods

    It's recommended to choose either Swift Package Manager or CocoaPods for integrating the library into your Content Extension. Mixing both methods might lead to conflicts or inconsistencies in your project setup.


    Approach 1 : Integrating via SPM

    • Add Package Dependency
      1. Navigate to File > Swift Packages > Add Package Dependency....

      Screenshot 1 (SPM)

      Screenshot 1 (SPM)
      1. Enter the URL of the library's repository: https://github.com/WebEngage/WEContentExtension.

      2. Click Next.

      3. Select the branch to use or enter a specific branch requirement (master).

      4. Click Next.

      Screenshot 1 (SPM)

      Screenshot 2 (SPM)
      1. Choose the target to which you want to add the dependency, i.e., your Content Extension target.

      2. Click Finish.

      Screenshot 1 (SPM)

      Screenshot 3 (SPM)

    OR

    Approach 2 : Integrating via CocoaPods

    • Prerequisites

      • Cocoapods should be installed inside your system

      • podfile should be available for your project

    • Edit Podfile

      • Open the Podfile using a text editor.

      • Add the library dependency to the Podfile. For example:

        # this target name should be your ContentExtension Name
        target 'ContentExtension' do
          pod 'WEContentExtension'
        end

        Note : Your target name should be the Content Extension name which you have entered while creating ContentExtension, Over here refer screenshot 3

    • Install Pods

      • Save the changes to the Podfile.

      • Install the pods by running the following command:

        pod install

  • Step 3 : Import and Use the WebEngage inside Content Extension

    • SWIFT

      1. Open NotificationViewController.swift

      2. Import WEContentExtension by adding code import WEContentExtension

      3. Remove all existing code from the class NotificationViewController

      4. Add subclassing to NotificationViewController with WEXRichPushNotificationViewController


      NotificationViewController.swift will look like above below code snippet

      import UIKit
      import UserNotifications
      import UserNotificationsUI
      
      // Import WebEngage Extension SDK
      import WEContentExtension
      
      // Subclassing current class with WebEngage provided class
      class NotificationViewController: WEXRichPushNotificationViewController {
      
          // remove all existing code inside this class
      
      }
    • Objective C

      1. Open NotificationViewController.m

      2. Import WEContentExtension

      3. Create Object of WEContentExtension

      4. Pass necessary information to WebEngage through above created object

      NotificationViewController.m will look like above below code snippet

      #import "NotificationViewController.h"
      #import <UserNotifications/UserNotifications.h>
      #import <UserNotificationsUI/UserNotificationsUI.h>
      
      // Step 1 : Importing WEContentExtension
      #import <WEContentExtension/WEContentExtension-Swift.h>
      
      @interface NotificationViewController () <UNNotificationContentExtension>
      
      @property IBOutlet UILabel *label;
      // Step 2 : Creating Object of content Extension
      @property WEXRichPushNotificationViewController *weRichPushVC;
      
      @end
      
      @implementation NotificationViewController
      
      // Step 3 : Pass necessary information to WebEngage
      - (void)viewDidLoad {
          if (_weRichPushVC == NULL){
              _weRichPushVC = [[WEXRichPushNotificationViewController alloc]init];
          }
          [_weRichPushVC setUpViewsWithParentVC:self];
          [super viewDidLoad];
      
      }
      
      - (void)didReceiveNotification:(UNNotification *)notification {
          [_weRichPushVC didReceiveNotification:notification];
      }
      
      - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{
          [_weRichPushVC didReceiveNotificationResponse:response completionHandler:completion];
      }
      @end

  • Step 4 : Configure ContentExtension-Info.plist

    Here's how you can go about it:

    • Open the Info.plist file for NotificationViewController

    • Expand NSExtension > NSExtensionAttributes

    • Look for UNNotificationExtensionCategory under NSExtensionAttributes. Add it if it is not present and set the type as Array In the Array items, add:

      • WEG_CAROUSEL_V1
      • WEG_RATING_V1
      • WEG_RICH_V1
      • WEG_RICH_V2
      • WEG_RICH_V3
      • WEG_RICH_V4
      • WEG_RICH_V5
      • WEG_RICH_V6
      • WEG_RICH_V7
      • WEG_RICH_V8
    • Set UNNotificationExtensionDefaultContentHidden under NSExtensionAttributes to YES

    • Add App Transport Security Settings key under Information Property List in NotificationViewController Info.plist files. Set Allow Arbitrary Loads to YES under App Transport Security Settings in both these files.

      (Note : Above step Not required if you are sure that image URLs provided for push on WebEngage dashboard will always use https.)

    • Source code snippet for Info.plist

          <key>NSExtension</key>
          <dict>
            <key>NSExtensionAttributes</key>
            <dict>
              <key>UNNotificationExtensionCategory</key>
              <array>
                <string>WEG_CAROUSEL_V1</string>
                <string>WEG_RATING_V1</string>
                <string>WEG_RICH_V1</string>
                <string>WEG_RICH_V2</string>
                <string>WEG_RICH_V3</string>
                <string>WEG_RICH_V4</string>
                <string>WEG_RICH_V5</string>
                <string>WEG_RICH_V6</string>
                <string>WEG_RICH_V7</string>
                <string>WEG_RICH_V8</string>
              </array>
              <key>UNNotificationExtensionDefaultContentHidden</key>
              <true/>
              <key>UNNotificationExtensionInitialContentSizeRatio</key>
              <real>1</real>
            </dict>
            <key>NSExtensionMainStoryboard</key>
            <string>MainInterface</string>
            <key>NSExtensionPointIdentifier</key>
            <string>com.apple.usernotifications.content-extension</string>
          </dict>



    • Info.plist shoul look like below screenshot

      InfoPlist

      info.plist

  • Step 5 : Create App Groups for all Targets

    App Groups allow your app and the WebEngageNotificationContentExtension to communicate when a notification is received, even if your app is not active. This is required for Confirmed Deliveries.

    • Select your Main App Target > Signing & Capabilities > + Capability > App Groups.
    • Within App Groups, click the + button.
    • Set the App Groups container to be group.YOUR_BUNDLE_IDENTIFIER.WEGNotificationGroup where YOUR_BUNDLE_IDENTIFIER is the same as your Main Application "Bundle Identifier".
    • Press OK and repeat for the NotificationViewController Target.
    • Screenshots



      Screenshot 1

      Screenshot 1


      Screenshot 1

      Screenshot 2


      Screenshot 1

      Screenshot 3

  • Step 6 : Build and Test

    • Build your project to ensure that the library integrates successfully.

    • Test your Content Extension to ensure that it functions as expected with the integrated library.


  • Migration from WebEngageAppEx to WEContentExtension

    • If you've been using the old content extension and want to switch to the new one, just stick to these instructions in the documentation:

    • Below are the steps to migrate from WebEngageAppEx to the WEContentExtension:

      • Remove pod 'WebEngageAppEx/ContentExtension' from the Content Extension Target NotificationViewController in the podfile.

      • Then Perform pod install

      • Then Follow Step Approach 2 : Cocoapods

      • After successfully completing the above step, let's move to the code section:

        • For Swift Users :

          • Open the NotificationViewController.swift file.
          • Replace import WebEngageAppEx with import WEContentExtension.
          • Done
        • For Objective-C Users:

          • Open the NotificationViewController.h file.
          • Remove the import statement #import <WebEngageAppEx/WEXRichPushNotificationViewController.h>.
          • Replace WEXRichPushNotificationViewController with UNNotificationContentExtension.
          • Open the NotificationViewController.m file.
          • Replace the code as given in Step Objective C

License

WEContentExtension is available under the MIT license. See the LICENSE file for more info.