iOS Notification Center

Inbox is a drop-in view controller which contains the read and unread push notifications. Even if the user has not clicked on a notification, it will be present in the Inbox and will be highlighted to signify it is unread status. The title and the look and feel of the view are also customisable.

Inbox view controller is added as a child view controller to your own controller. This helps you get the delegate callback in the same controller, which you can further use for navigation to different screens.

SDK Installation

From MoEngage-iOS-SDK version 8.2.0 ,Inbox module is separated from the SDK to a separate module as MoEngageInbox and hence has to be added separately.

Version

Install using CocoaPod

Integrate MoEngageInbox framework by adding the dependency in the podfile as show below.

Ruby
pod 'MoEngageInbox','~>1.2.0'

Now run pod install to install the framework

Install using Swift Package Manager

MoEngageInbox is supported through SPM from SDK version 1.2.0. To integrate use the following git hub url link and set the branch as master or version as 1.2.0 and above https://github.com/moengage/MoEngage-iOS-Inbox.git

Inbox Setup Checklist

Make sure the following items are implemented before using the Inbox Module:

  1. Update the MoEngage-iOS-SDK to version >= 8.2.0

  2. Integrate the MoEngageInbox module of version >= 1.2.0
  3. Implement Notification Service Extension and Integrate MoEngageRichNotiifcation(>= 6.2.0).

  4. AppGroupID is set in App Target Capabilities and the same is passed to the SDK.

  5. AppGroupID is set in Notification Service Extension Target Capabilities and the same is passed to the MoEngageRichNotification SDK.

 

APP GROUP ID:

Make sure the App Group ID configured for both the App Target and the Notification Service Extension Target are the same.

How to use Inbox?

  1. Import MoEngageInbox in your View Controller.
  2. Create a property - @property(nonatomic, strong) MOInboxViewController *inboxController.
  3. In viewDidLoad, add the below code to fetch MOInboxViewController
Swift Objective-C
MOInbox.sharedInstance.getInboxViewController(withUIConfiguration: nil, forAppID: "YOUR APP ID") { inboxController in
     self.inboxController = inboxController
}

Push/Present the MOInboxViewController

In order for the SDK to handle the transition, use one of the methods.

Swift Objective-C
MOInbox.sharedInstance.pushInboxViewController(toNavigationController: self.navigationController, withUIConfiguration: nil)
    
// Present 
MOInbox.sharedInstance.presentInboxViewController(withUIConfiguration: nil)

MOInboxViewControllerDelegate Methods

Use MOInboxViewControllerDelegate protocol for getting the callbacks from the Inbox Module:

Swift Objective-C
extension NotificationsViewController: MOInboxViewControllerDelegate {
//Called when inbox cell is selected
func inboxEntryClicked(_ inboxItem: MOInboxEntry) {
     print("Inbox Clicked")
}
    
//Called when inbox item is deleted
func inboxEntryDeleted(_ inboxItem: MOInboxEntry) {
     print("Inbox item deleted")
}

// Called when MOInboxViewController is dismissed after being presented
func inboxViewControllerDismissed() {
     print("Dismissed")
}
}

Set MOInboxViewControllerDelegate by passing the delegate as parameter in the below functions.

Swift Objective-C
//Push
MOInbox.sharedInstance.pushInboxViewController(toNavigationController: self.navigationController!, withUIConfiguration: nil, withInboxWithControllerDelegate: self)

//Present
MOInbox.sharedInstance.presentInboxViewController(withUIConfiguration: nil, withInboxWithControllerDelegate: self)
        
//Fetch MOInboxViewController
MOInbox.sharedInstance.getInboxViewController(withUIConfiguration: nil, withInboxWithControllerDelegate: self, forAppID: "YOUR APP ID") { inboxController in
     self.inboxController = inboxController
 }

Customizing Appearance

  1. You can push/present your controller. If you push your controller, make sure to add “Done” or “Cancel” button as a UIBarButtonItem to dismiss your View Controller.
  2. You can get the delegate callback of the click action on inbox cells.
  3. You can use this data for tracking events or navigation to another screen.
  4. You can customize the look and feel of the inbox view controller using the method:
Swift Objective-C
let configuration = MOInboxUIConfiguration()
configuration.cellDefaultBackgroundColor = .red
configuration.cellHeaderLabelFont = UIFont.systemFont(ofSize: 15)
configuration.cellMessageLabelFont = UIFont.systemFont(ofSize: 13)
configuration.cellSelectionTintColor = .red
configuration.cellHeaderLabelTextColor = .white
configuration.cellMessageLabelTextColor = .white
configuration.cellUnreadBackgroundColor = .blue
            
let navigationBarStyle = MOInboxNavigationBarStyle()
navigationBarStyle.navigationBarColor = .black
navigationBarStyle.navigationBarTintColor = .blue
navigationBarStyle.navigationBarTitleColor = .blue
navigationBarStyle.navigationBarTransluscent = false
configuration.navigationBarStyle = navigationBarStyle

//Present
MOInbox.sharedInstance.presentInboxViewController(withUIConfiguration: configuration, forAppID: "YOUR APP ID")

//Push
MOInbox.sharedInstance.pushInboxViewController(toNavigationController: self.navigationController!, withUIConfiguration: configuration, forAppID: "APP ID")

//Fetch MOInboxViewController
MOInbox.sharedInstance.getInboxViewController(withUIConfiguration: configuration, forAppID: "YOUR APP ID") { controller in
}

Self Handled Inbox

Fetch Inbox Messages:

Inbox can be completely customized now. Use getMessagesWithCompletionBlock: to fetch the inbox messages.

Swift Objective-C
MOInbox.sharedInstance.getInboxMessages(forAppID: "YOUR APP ID") { inboxMessages, account in
     print("Received Inbox messages")
 }
 

Mark a notification as Read:

An inbox notification can be marked as read with the method markInboxNotificationReadForCampaignID: by providing the campaign ID of the notification while calling the method. The method will return the updated notification payload where the isRead key will be set to true.

Swift Objective-C
//Get the MOInboxEntry instance
let pushModel = inboxMessages[]

if !pushModel.isRead {
    MOInbox.sharedInstance.markInboxNotificationClicked(withCampaignID: pushModel.campaignID)
}

Track Inbox Notification Clicks:

An inbox notification click can be tracked by using method trackInboxNotificationClickForCampaignID: by providing the campaign ID of the notification while calling the method.

Swift Objective-C
//Get the MOInboxEntry instance
 let pushModel = inboxMessages[]
 MOInbox.sharedInstance.trackInboxClick(withCampaignID: pushModel.campaignID)

Process the Inbox Clicks:

If you want to perform the actions supported by the SDK(i.e, rich landing, deep linking, coupon code etc) associated with the notifications on clicking the entry in Inbox call processInboxNotificationWithCampaignID: method as shown below.

Swift Objective-C
//Get the MoInboxEntry instance
 let pushModel = inboxMessages[]
 MOInbox.sharedInstance.processInboxNotification(withCampaignID: pushModel.campaignID)

Get Unread Notifications count:

You can obtain the unread notifications count from the Inbox by using getUnreadNotifictionCount method as shown below:

Swift Objective-C
//Get Unread Notifications count 
MOInbox.sharedInstance.getUnreadNotificationCount() { count, accountMeta in
    print("Unread message count is \(count)")
}

Deleting Messages

Use this method to remove all the messages currently stored in inbox.

Swift Objective-C
MOInbox.sharedInstance.removeInboxMessages()

Use the below method to remove the single message stored in inbox by passing the Campaign ID.

Swift Objective-C
MOInbox.sharedInstance.removeInboxMessage(withCampaignID: "YOUR CAMPAIGN ID")

Methods deprecated in SDK version 4.4.0

We have revamped the Inbox Module in the SDK version 4.4.0 and following this, we have deprecated MOInboxPushDataModel class and use MOInboxModel class instances as the model object for notifications. Along with this, we have also deprecated few of the existing methods of MOInbox as listed below:

Objective-C
+(NSArray *)getInboxMessages __deprecated_msg("This method is deprecated as the payload structure has changed, this method will be removed in SDK Version 5.0.0. Use getInboxMessagesWithCompletionBlock: instead");

+(void)trackInboxNotificationClickForCampaign:(MOInboxPushDataModel*)campaignObj andIsFirstClick:(BOOL)isFirstClick __deprecated_msg("This method is deprecated as MOInboxPushDataModel Class is depreacted, this method will be removed in SDK Version 5.0.0. Use trackInboxNotificationClickWithCampaignID: instead");

+(void)processInboxNotificationOnClickForCampaign:(MOInboxPushDataModel*)campaignObj __deprecated_msg("This method is deprecated as MOInboxPushDataModel Class is depreacted, this method will be removed in SDK Version 5.0.0. Use processInboxNotificationWithCampaignID: instead");

+(NSMutableDictionary*)markNotificationReadWithCampaignID:(NSString*)cid __deprecated_msg("This method is deprecated as MOInboxPushDataModel Class is depreacted, this method will be removed in SDK Version 5.0.0. Use markInboxNotificationClickedWithCampaignID: instead");

+(void)writeArrayToFile:(NSMutableArray *)anArray __deprecated_msg("Method Deprecated. From SDK Version 5.0.0 you will not be able to change the inbox file content.");

These methods will be removed from the SDK version 5.0.0, therefore make sure you have updated all the Inbox feature to use the newer APIs.

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