App Inbox Integration

App inbox is essentially a screen within an app where all your notifications will be listed. App inbox offers you a way to make your push notifications persistent that users can refer back at any point.

👍

Read more about how app inbox feature works here

This guide will explain how to integrate app inbox.

Step 1: Adding SDK dependency - CocoaPods

  1. In the Podfile add the SmartechAppInbox-iOS-SDK as a dependency.
pod 'SmartechAppInbox-iOS-SDK', '~> <<appinbox_sdk_ios_version>>'
  1. Run the following command to update the added pod in your Podfile.
pod install

Once your installation is complete, you will have to open the workspace file (YOUR-PROJECT-NAME.xcworkspace) that is created.

Step 2: Integration with default UI

To use our default UI to show notification and present the activity/controller within their application.

SMTAppInboxViewController  *appInboxController = 
[[SmarttechAppInbox sharedInstance] getAppInboxViewController];
let appInboxController = SmartechAppInbox.sharedInstance().getViewController()

Step 3: Integration with Custom UI

Category based data

Every AppInbox Message belongs to a specific category and we can use this data to create a dropdown on the menu to display the list of available categories to users.

The below method can be used to get a list of available categories.

NSArray <SMTAppInboxCategoryModel *> *appInboxCategoryArray;
appInboxCategoryArray  = [[NSArray alloc] init];
appInboxCategoryArray = [[SmartechAppInbox sharedInstance] getAppInboxCategoryList];
var appInboxCategoryArray: [SMTAppInboxCategoryModel]?
appInboxCategoryArray = []
appInboxCategoryArray = SmartechAppInbox.sharedInstance().getAppInboxCategoryList()

The below method can be used to filter the AppInbox messages list based on the category selected by the user. It takes an ArrayList of strings as a parameter.

NSMutableArray <SMTAppInboxMessage *> *appInboxArray;
appInboxArray  = [[NSArray alloc] init];
appInboxArray = [[[SmartechAppInbox sharedInstance] getAppInboxMessageWithCategory:appInboxCategoryArray] mutableCopy];
var appInboxArray: [SMTAppInboxMessage]?
appInboxArray = []
appInboxArray = SmartechAppInbox.sharedInstance().getMessageWithCategory(appInboxCategoryArray as? NSMutableArray)
NSMutableArray <SMTAppInboxMessage *> *appInboxArray;

- (void)refreshInboxDataSourceWithCategory {
  self.appInboxArray  = [[NSArray alloc] init];
  self.appInboxArray = [[[SmartechAppInbox sharedInstance] getAppInboxMessageWithCategory:appInboxCategoryArray] mutableCopy];
  
   dispatch_async(dispatch_get_main_queue(), ^{
        //Refresh table View
   });
}
var appInboxArray: [SMTAppInboxMessage]?

func refreshInboxDataSourceWithCategory() {
    appInboxArray = []
    appInboxArray = SmartechAppInbox.sharedInstance().getMessageWithCategory(appInboxCategoryArray as? NSMutableArray)

    DispatchQueue.main.async {
        //Refresh table View
    }
}

Pull to refresh

[[SmartechAppInbox sharedInstance] getAppInboxMessage:[[SmartechAppInbox sharedInstance] pullToRefreshParam] withCompletionHandler:^(NSError *error,BOOL status) {
    if (status) {
       	// Refresh your data
         [self refreshInboxDataSourceWithCategory];
     }
 }];
SmartechAppInbox.sharedInstance().getMessage(SmartechAppInbox.sharedInstance().getPullToRefreshParameter()) { [] error, status in
   if (status) {
      // Refresh your data
      self.refreshInboxDataSourceWithCategory()
   }
}

Pagination

[[SmartechAppInbox sharedInstance] getAppInboxMessage:[[SmartechAppInbox sharedInstance] getPaginationParameter] withCompletionHandler:^(NSError *error,BOOL status) {
      if (status) {
       	// Refresh your data
         [self refreshInboxDataSourceWithCategory];
      }
 }];
SmartechAppInbox.sharedInstance().getMessage(SmartechAppInbox.sharedInstance().getPaginationParameter()) {  error, status in
   if (status) {
      // Refresh your data
      self.refreshInboxDataSourceWithCategory()
   }
}

Fetching data from DB

You can use the below method to fetch the data from the database and it can be also used to show data in an offline state. This method accepts SMTAppInboxMessageType as a parameter.

SMTAppInboxMessageType is an enum and it has 3 values.
ALL_MESSAGE - Get both read and unread messages from DB.
READ_MESSAGE - Get only read messages from DB.
UNREAD_MESSAGE - Get only unread messages from DB.

[[[SmartechAppInbox sharedInstance] getAppInboxMessages:ALL_MESSAGE] mutableCopy];
SmartechAppInbox.sharedInstance().getAppInboxMessages(SMTAppInboxMessageType.ALL_MESSAGE)

AppInbox Message Count

To show the count of all, read and unread messages, we can call the below method to get their respective count. This method accepts SMTAppInboxMessageType as a parameter.

SMTAppInboxMessageType is an enum and it has 3 values.
ALL_MESSAGE - Get count of both read and unread messages from DB.
READ_MESSAGE - Get count of only read messages from DB.
UNREAD_MESSAGE - Get count of only unread messages from DB.

[[SmartechAppInbox sharedInstance] getAppInboxMessageCount:ALL_MESSAGE]
SmartechAppInbox.sharedInstance().getMessageCount(SMTAppInboxMessageType.ALL_MESSAGE)

User Events

You also need to send Viewed, Clicked and Dismissed events to SDK for every action performed on the AppInbox message by the user.

Viewed
Send this event once the AppInbox message is visible to the user and It should be sent only one time for each AppInbox message. This method accepts the payload of the AppInbox message as a parameter.

// inboxMesaage - Payload or object of SMTAppInboxMessage 
[[SmartechAppInbox sharedInstance] markMessageAsViewed:inboxMesaage];
// inboxMesaage - Payload or object of SMTAppInboxMessage 
SmartechAppInbox.sharedInstance().markMessage(asViewed: inboxMessage)

Clicked
Onclick of AppInbox message, you need to send this event to SDK. This method takes 2 parameters that are deeplink and payload of AppInbox message.

// actionDeeplink - send deeplink as a String
[[SmartechAppInbox sharedInstance]markMessageAsClicked:inboxMesaage withDeeplink:actionDeeplink];
// actionDeeplink - send deeplink as a String
SmartechAppInbox.sharedInstance().markMessage(asClicked: inboxMessage, withDeeplink:actionDeeplink)

Dismissed
You can use this method to mimic the feature of swipe to delete the messages from your TableView. You need to manually remove the message from the TableView and next time when you will fetch the data from the DB, this message will be not present.

SMTAppInboxMessage *inboxMessage = [self.appInboxArray objectAtIndex:indexPath.row];
if (inboxMessage) {
   [[SmartechAppInbox sharedInstance] markMessageAsDismissed:inboxMessage withCompletionHandler:^(NSError *error, BOOL status) {
        if (status) {
            //Remove data from array and refresh the table view
        }
     }];
}
SmartechAppInbox.sharedInstance().markMessage(asDismissed: inboxMessage) {  error, status in
     if (status) {
         //Remove data from array and refresh the table view
     }  
}