> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-sdk-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

## Install using Swift Package Manager

MoEngageInbox is supported through SPM from SDK version 1.2.0. To integrate, use the  GitHub url [https://github.com/moengage/apple-sdk.git](https://github.com/moengage/apple-sdk.git) for SDK versions equal and above 9.23.0, or [https://github.com/moengage/MoEngage-iOS-SDK.git](https://github.com/moengage/MoEngage-iOS-SDK.git) for other SDK versions link and set the branch as master or required version.

## Install using CocoaPod

<Info>
  **Information**

  CocoaPods is being deprecated. MoEngage recommends using Swift Package Manager for all new integrations. For more info on CocoaPods, refer to [CocoaPods Integration Guide](/developer-guide/ios-sdk/sdk-integration/basic/integration-through-cocoa-pods).
</Info>

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.

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

<CodeGroup>
  ```ruby Ruby wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  pod 'MoEngage-iOS-SDK/Inbox',
  ```
</CodeGroup>

Now run `pod install` to install the framework

# Inbox Setup Checklist

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

1. Update the MoEngage-iOS-SDK to version >= 9.0.0
2. Integrate the MoEngageInbox module of version >= 2.0.0
3. [Implement Notification Service Extension](/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#tracking-and-analytics-verification) and Integrate [MoEngageRichNotifcation](https://cocoapods.org/pods/MORichNotification)(>= 7.0.0).
4. AppGroupID is set in **App Target** [Capabilities](/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#step-1-implement-notification-service-extension-nse) and the [same is passed to the SDK](/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#step-1-implement-notification-service-extension-nse).
5. AppGroupID is set in **Notification Service Extension Target** [Capabilities](/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#step-1-implement-notification-service-extension-nse) and the [same is passed to the MoEngageRichNotification SDK](/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#step-1-implement-notification-service-extension-nse).

<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**.
</Warning>

# How to use Inbox?

1. Import `MoEngageInbox` in your View Controller.
2. Create a property - @property(nonatomic, strong) MoEngageInboxViewController \*inboxController.
3. In viewDidLoad, add the below code to fetch MoEngageInboxViewController

   <CodeGroup>
     ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
     MoEngageSDKInbox.sharedInstance.getInboxViewController(withUIConfiguration: nil, withInboxWithControllerDelegate: nil, forAppID: "YOUR Workspace ID") { inboxController in
          self.inboxController = inboxController
     }
     ```

     ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
     [[MoEngageSDKInbox sharedInstance] getInboxViewControllerWithUIConfiguration:nil withInboxWithControllerDelegate:nil forAppID:@"YOUR Workspace ID" withCompletionBlock:^(MoEngageInboxViewController * _Nullable) {
                 self.inboxController = inboxController;
     }];
     ```
   </CodeGroup>

# Push/Present the MoEngageInboxViewController

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

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  MoEngageSDKInbox.sharedInstance.pushInboxViewController(toNavigationController: self.navigationController!, withUIConfiguration: nil)
      
  // Present 
  MoEngageSDKInbox.sharedInstance.presentInboxViewController(withUIConfiguration: nil)
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}

  [[MoEngageSDKInbox sharedInstance] pushInboxViewControllerToNavigationController:navigationController withUIConfiguration:nil withInboxWithControllerDelegate:nil forAppID:@"YOUR Workspace ID"];

  // Present
  [[MoEngageSDKInbox sharedInstance] presentInboxViewControllerWithUIConfiguration:nil withInboxWithControllerDelegate:nil forAppID:@"YOUR Workspace ID"];
  ```
</CodeGroup>

# MoEngageInboxViewControllerDelegate Methods

Use [*MoEngageInboxViewControllerDelegate*](https://moengage.github.io/ios-api-reference/Protocols/MoEngageInboxViewControllerDelegate.html) protocol for getting the callbacks from the Inbox Module:

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  extension NotificationsViewController: MoEngageInboxViewControllerDelegate {
  //Called when inbox cell is selected
  func inboxEntryClicked(_ inboxItem: MoEngageInboxEntry) {
       print("Inbox Clicked")
  }
      
  //Called when inbox item is deleted
  func inboxEntryDeleted(_ inboxItem: MoEngageInboxEntry) {
       print("Inbox item deleted")
  }

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

  ```objective-c Objective-C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Called when inbox cell is selected
  - (void)inboxEntryClicked:(MoEngageInboxEntry *)inboxItem {
      NSLog(@"Inbox item Clicked");
  }

  //Called when inbox item is deleted
  - (void)inboxEntryDeleted:(MoEngageInboxEntry *)inboxItem {
      NSLog(@"Inbox item Deleted");
  }

  // Called when MoEngageInboxViewController is dismissed after being presented
  - (void)inboxViewControllerDismissed {
      NSLog(@"Inbox Dismissed");
  }
  ```
</CodeGroup>

Set [*MoEngageInboxViewControllerDelegate*](https://moengage.github.io/ios-api-reference/Protocols/MoEngageInboxViewControllerDelegate.html) by passing the delegate as parameter in the below functions.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Push
  MoEngageSDKInbox.sharedInstance.pushInboxViewController(toNavigationController: self.navigationController!, withUIConfiguration: nil, withInboxWithControllerDelegate: self)

  //Present
  MoEngageSDKInbox.sharedInstance.presentInboxViewController(withUIConfiguration: nil, withInboxWithControllerDelegate: self)
          
  //Fetch MoEngageInboxViewController
  MoEngageSDKInbox.sharedInstance.getInboxViewController(withUIConfiguration: nil, withInboxWithControllerDelegate: self, forAppID: "YOUR Workspace ID") { inboxController in
       self.inboxController = inboxController
   }
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Push
  [[MoEngageSDKInbox sharedInstance] pushInboxViewControllerToNavigationController:navigationController withUIConfiguration:nil withInboxWithControllerDelegate:self forAppID:@"YOUR Workspace ID"];

  //Present
  [[MoEngageSDKInbox sharedInstance] presentInboxViewControllerWithUIConfiguration:nil withInboxWithControllerDelegate:self forAppID:@"YOUR Workspace ID"];

  //Fetch MoEngageInboxViewController
  [[MoEngageSDKInbox sharedInstance] getInboxViewControllerWithUIConfiguration:nil withInboxWithControllerDelegate:self forAppID:@"YOUR Workspace ID" withCompletionBlock:^(MoEngageInboxViewController * _Nullable inboxController) {
            self.inboxController = inboxController;
      }];
  }
  ```
</CodeGroup>

# 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:

   <CodeGroup>
     ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
     let configuration = MoEngageInboxUIConfiguration()
     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 = MoEngageInboxNavigationBarStyle()
     navigationBarStyle.navigationBarColor = .black
     navigationBarStyle.navigationBarTintColor = .blue
     navigationBarStyle.navigationBarTitleColor = .blue
     navigationBarStyle.navigationBarTransluscent = false
     configuration.navigationBarStyle = navigationBarStyle

     //Present
     MoEngageSDKInbox.sharedInstance.presentInboxViewController(withUIConfiguration: configuration, forAppID: "YOUR Workspace ID")

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

     //Fetch MoEngageInboxViewController
     MoEngageSDKInbox.sharedInstance.getInboxViewController(withUIConfiguration: configuration, forAppID: "YOUR Workspace ID") { controller in
     }
     ```

     ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
     MoEngageInboxUIConfiguration* configuration = [[MoEngageInboxUIConfiguration alloc] init];
     configuration.cellDefaultBackgroundColor = [UIColor redColor];
     configuration.cellHeaderLabelFont =[UIFont fontWithName:@"AvenirNext-Bold" size:18];
     configuration.cellMessageLabelFont = [UIFont fontWithName:@"AvenirNext-Bold" size:15];
     configuration.cellHeaderLabelTextColor = [UIColor whiteColor];
     configuration.cellMessageLabelTextColor =[UIColor whiteColor];
     configuration.cellUnreadBackgroundColor = [UIColor blueColor];
         
     MoEngageInboxNavigationBarStyle* navigationBarStyle = [[MoEngageInboxNavigationBarStyle alloc] init];
     navigationBarStyle.navigationBarColor = [UIColor blackColor];
     navigationBarStyle.navigationBarTintColor = [UIColor blueColor];
     navigationBarStyle.navigationBarTitleColor = [UIColor blueColor];
     navigationBarStyle.navigationBarTransluscent = true;
     configuration.navigationBarStyle = navigationBarStyle;
         
      //Present
     [[MoEngageSDKInbox sharedInstance] presentInboxViewControllerWithUIConfiguration:configuration withInboxWithControllerDelegate:self forAppID:@"YOUR Workspace ID"];
         
     //Push
     [[MoEngageSDKInbox sharedInstance] pushInboxViewControllerToNavigationController:navigationController withUIConfiguration:configuration withInboxWithControllerDelegate:nil forAppID:@"YOUR Workspace ID"];
         
     //Fetch MoEngageInboxViewController
     [[MoEngageSDKInbox sharedInstance] getInboxViewControllerWithUIConfiguration:configuration withInboxWithControllerDelegate:nil forAppID:@"YOUR Workspace ID" withCompletionBlock:^(MoEngageInboxViewController * _Nullable inboxController) {
     }];
     ```
   </CodeGroup>

# Self Handled Inbox

## Fetch Inbox Messages:

Inbox can be completely customized now. Use [*getInboxMessages(forAppID:withCompletionBlock:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)getInboxMessagesForAppID:withCompletionBlock:) to fetch the inbox messages.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  MoEngageSDKInbox.sharedInstance.getInboxMessages(forAppID: "YOUR Workspace ID") { inboxMessages, account in
       print("Received Inbox messages")
   }
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  [[MoEngageSDKInbox sharedInstance] getInboxMessagesForAppID:@"YOUR Workspace ID" withCompletionBlock:^(NSArray * _Nonnull inboxEntry, MoEngageAccountMeta * _Nullable accountMeta) {
              NSLog(@"Received Inbox messages");
  }];
  ```
</CodeGroup>

## Mark a notification as Read:

An inbox notification can be marked as read with the method [*markInboxNotificationClicked(withCampaignID:forAppID:completionHandler)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)markInboxNotificationClickedWithCampaignID:forAppID:completionHandler:) 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.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Get the MoEngageInboxEntry instance
  let pushModel = inboxMessages[]

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

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //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
  }
  ```
</CodeGroup>

## Track Inbox Notification Clicks:

An inbox notification click can be tracked by using method [*trackInboxClick(withCampaignID:forAppID:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)trackInboxClickWithCampaignID:forAppID:) by providing the campaign ID of the notification while calling the method.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Get the MoEngageInboxEntry instance
   let pushModel = inboxMessages[]
   MoEngageSDKInbox.sharedInstance.trackInboxClick(withCampaignID: pushModel.campaignID)
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //An example of marking the inbox message as read
  MOInboxModel *pushDataObj = [self.inboxMessagesArray objectAtIndex:<get the index>];
  [[MOInboxHandler sharedInstance] trackInboxNotificationClickForCampaignID:pushDataObj.campaignID];
  ```
</CodeGroup>

## 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 [*processInboxNotification(withCampaignID:forAppID:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)processInboxNotificationWithCampaignID:forAppID:) method as shown below.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Get the MoEngageInboxEntry instance
   let pushModel = inboxMessages[]
   MoEngageSDKInbox.sharedInstance.processInboxNotification(withCampaignID: pushModel.campaignID)
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
   //An example of process the notification actions
  MOInboxModel *pushDataObj = [self.inboxMessagesArray objectAtIndex:<get the index>];
  [[MoEngageSDKInbox sharedInstance] processInboxNotificationWithCampaignID:pushDataObj.campaignID forAppID:@"YOUR Workspace ID"];
  ```
</CodeGroup>

## Get Unread Notifications count:

You can obtain the unread notifications count from the Inbox by using [*getUnreadNotificationCount(forAppID:withCompletionBlock:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)getUnreadNotificationCountForAppID:withCompletionBlock:)  method as shown below:

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Get Unread Notifications count 
  MoEngageSDKInbox.sharedInstance.getUnreadNotificationCount() { count, accountMeta in
      print("Unread message count is \(count)")
  }
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  //Get Unread Notifications count 
  [[MoEngageSDKInbox sharedInstance] getUnreadNotificationCountForAppID:@"YOUR Workspace ID" withCompletionBlock:^(NSInteger count, MoEngageAccountMeta * _Nullable accountMeta) {
          NSLog(@"Fetched unread message Count");
  }];
  ```
</CodeGroup>

## Deleting Messages

Use [*removeInboxMessages(forAppID:completionHandler:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)removeInboxMessagesForAppID:completionHandler:) method to remove all the messages currently stored in inbox.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  MoEngageSDKInbox.sharedInstance.removeInboxMessages { success in
                      print("Removed all inbox messages \(success)")
                  }
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  [[MoEngageSDKInbox sharedInstance] removeInboxMessagesForAppID:@"YOUR Workspace ID" completionHandler:^(BOOL) {
          // Add your code
      }];
  ```
</CodeGroup>

Use [*removeInboxMessage(withCampaignID:forAppID:completionHandler:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKInbox.html#/c:@M@MoEngageInbox@objc\(cs\)MoEngageSDKInbox\(im\)removeInboxMessageWithCampaignID:forAppID:completionHandler:) method to remove the single message stored in inbox by passing the Campaign ID.

<CodeGroup>
  ```swift Swift wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  MoEngageSDKInbox.sharedInstance.removeInboxMessage(withCampaignID: "YOUR CAMPAIGN ID")
  ```

  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  [[MoEngageSDKInbox sharedInstance] removeInboxMessageWithCampaignID:@"CAMPAIGN ID" forAppID:@"YOUR Workspace ID"];
  ```
</CodeGroup>

# 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:

<CodeGroup>
  ```objective-c Objective C wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  +(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.");
  ```
</CodeGroup>

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

<Info>
  **Information**

  The MoEngage SDK only synchronizes push data with the Notification Center when the app is launched for the first time or when it returns to the foreground from the background.
</Info>
