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.
Inbox Setup Checklist
Make sure the following items are implemented before using the Inbox Module:
-
Update the MoEngage-iOS-SDK to version >= 4.4.0.
-
Implement Notification Service Extension and Integrate MORichNotiifcation(>= 3.0.1).
-
AppGroupID is set in App Target Capabilities and the same is passed to the SDK.
-
AppGroupID is set in Notification Service Extension Target Capabilities and the same is passed to the MORichNotification SDK.
warning |
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?
- Import
MOMessaging
in your View Controller. - Create a property - @property(nonatomic, strong) MOInboxViewController *myInboxController.
- In viewDidLoad, add
self.myInboxController = MOInbox.initializeInbox(on: self)
self.myInboxController = [MOInbox initializeInboxOnController:self];
You are all set. This will add Inbox as a child controller to your view controller.
MOInboxCellSelectedDelegate Methods
In case if you want to do perform any action on clicking of the Inbox notification, make use of the MOInboxCellSelectedDelegate. On setting the `delegate` of the `MOInboxViewController` you will get the `inboxCellSelectedWithPushDict:` and `inboxCellSelectedWithData:` callback where you will get the push notification payload and `app_extra` dict in the notification payload respectively as shown below :
func inboxCellSelected(withData dataDict: [AnyHashable : Any]!) {
print("Data Dict : \(dataDict)")
}
func inboxCellSelected(withPushDict pushDict: [AnyHashable : Any]!) {
print("Push Dict : \(pushDict)")
}
-(void)inboxCellSelectedWithData:(NSDictionary *)dataDict{
NSLog(@"data dict is %@", dataDict);
}
-(void)inboxCellSelectedWithPushDict:(NSDictionary *)pushDict{
NSLog(@"push dict is %@", pushDict);
}
Click Processing of Inbox Notifications
To enable click processing in Default Inbox implementation set shouldProcessNotificationActions
of InboxViewController instance to true
as shown below:
self.myInboxController?.shouldProcessNotificationActions = true
self.myInboxController.shouldProcessNotificationActions = true
Customizing Appearance
- 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.
- You can get the delegate callback of the click action on inbox cells.
- You can use this data for tracking events or navigation to another screen.
- You can customize the look and feel of the inbox view controller using the method:
self.myInboxController?.customiseInbox(withCellTextColor: UIColor.darkGray, fontForReadMsg: UIFont.systemFont(ofSize: 15.0, weight: .bold), fontForUnreadMsg: UIFont.systemFont(ofSize: 15.0, weight: .regular), dateTextColor:UIColor.lightGray, font: UIFont.systemFont(ofSize: 10.0, weight: .light), cellBackgroundColor: UIColor.clear)
[self.myInboxController customiseInboxWithCellTextColor:[UIColor blackColor] fontForReadMsg:[UIFont fontWithName:@"AvenirNext-Regular" size:18] fontForUnreadMsg:[UIFont fontWithName:@"AvenirNext-Bold" size:18] dateTextColor:[UIColor grayColor] font:nil cellBackgroundColor:[UIColor clearColor]];
You can use the method setDataWithMessage in the table view cell to set the data, which sets the message, the font and time of the message.
Alternatively, you can build your own UI and not chose to call this method and set the data in your own method.
Self Handled Inbox
Fetch Inbox Messages:
Inbox can be completely customized now. Use getMessagesWithCompletionBlock:
to fetch the inbox messages.
MOInbox.getMessagesWithCompletionBlock { (messages) in
if let messages = messages{
self.inboxMessages = messages
}
}
[MOInbox getInboxMessagesWithCompletionBlock:^(NSArray<MOInboxModel *> *inboxMessages) {
self.inboxMessagesArray = inboxMessages
}]
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.
//Get the MOInboxModel instance
let pushModel = self.inboxMessages[<get index>]
if !pushModel.isRead {
MOInbox .markNotificationClicked(withCampaignID: pushModel.campaignID)
}
//An example of marking the inbox message as read
MOInboxModel *pushDataObj = [self.inboxMessagesArray objectAtIndex:<get the index>];
if (!pushDataObj.isRead){
[[MOInboxHandler sharedInstance] markInboxNotificationReadForCampaignID:pushDataObj.campaignID];
//Rest of the implementation
}
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.
//Get the MOInboxModel instance
let pushModel = self.inboxMessages[<get index>]
MOInbox.trackInboxNotificationClick(withCampaignID: pushModel.campaignID)
//An example of marking the inbox message as read
MOInboxModel *pushDataObj = [self.inboxMessagesArray objectAtIndex:<get the index>];
[[MOInboxHandler sharedInstance] trackInboxNotificationClickForCampaignID:pushDataObj.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.
//Get the MOInboxModel instance
let pushModel = self.inboxMessages[<get index>]
MOInbox.processInboxNotification(withCampaignID: pushModel.campaignID)
//An example of process the notification actions
MOInboxModel *pushDataObj = [self.inboxMessagesArray objectAtIndex:<get the index>];
[MOInbox processInboxNotificationWithCampaignID:pushDataObj.campaignID];
Get Unread Notifications count:
You can obtain the unread notifications count from the Inbox by using getUnreadNotifictionCount
method as shown below:
//Get Unread Notifications count
let unreadCount = MOInbox.getUnreadNotifictionCount()
//Get Unread Notifications count
NSInteger unreadCount = [MOInbox getUnreadNotifictionCount];
Disabling Inbox
If you wish to disable inbox, set the property disableInbox. This property has to be set before the initialze call.
MoEngage.sharedInstance().disableInbox = true
[MoEngage sharedInstance].disableInbox = YES;
Deleting Messages
Use this method to remove all the messages currently stored in inbox.
MOInbox.removeInboxMessages()
[MOInbox removeInboxMessages]
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:
+(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.