Prerequisites

This is the quickest way to add App Inbox functionality to your iOS app. In this setup app will be using the default notification center view controller provided by the SDK for displaying inbox messages and managing them. You can also customize the appearance of the notification center view controller to match your app theme.

Pod Install

Starting from Castled iOS version 4.0.2, AppInbox functionality is separated as a new module CastledInbox. Add the module pod as dependency in the app pod file.

pod 'CastledInbox'

Save the Podfile and run the following command in the terminal to install the SDK:

pod install

Displaying App Inbox content

To facilitate the effortless display of App Inbox content, the SDK provides a default view controller: CastledInboxViewController. This controller is designed to showcase inbox cards and can be integrated within your app in two primary ways:

Using Navigation Controller

Embed CastledInboxViewController within your existing navigation flow for a consistent user experience.

import CastledInbox

func pushViewController() {
    let inboxViewController = CastledInbox.sharedInstance.getInboxViewController(withUIConfigs: nil, andDelegate: self)
    self.navigationController?.pushViewController(inboxViewController, animated: true)
}

Using a Modal

Present the App Inbox cards in a modal view, suitable for focused interactions.

  import CastledInbox

  func presentViewController() {
      let inboxViewController = CastledInbox.sharedInstance.getInboxViewController(withUIConfigs: nil, andDelegate: self)
      self.present(inboxViewController, animated: true, completion: nil)
  }

Handling Inbox Item Selection

To effectively capture and act upon interactions with App Inbox items, SDK offers the CastledInboxViewControllerDelegate protocol. By adopting this protocol, you can tap into the callback provided when a user selects an item from the inbox.

swift
@objc public protocol CastledInboxViewControllerDelegate {
    // Called when a Card is clicked by the user
    @objc optional func didSelectedInboxWith(_ buttonAction: CastledButtonAction, inboxItem: CastledInboxItem)

}

Integration Steps:

  1. Ensure your view controller conforms to the CastledInboxViewControllerDelegate protocol.
  2. Implement the didSelectedInboxWith((\_:buttonAction:, inboxItem:) delegate method.
    class MyViewController: CastledInboxViewControllerDelegate {
    ...
        // Implement the callback method
        func didSelectedInboxWith(_ buttonAction: CastledButtonAction, inboxItem: CastledInboxItem) {
            print("didSelectedInboxWith title '\(buttonAction.buttonTitle ?? "")' uri '\(buttonAction.actionUri ?? "")'kvPairs \(buttonAction.keyVals) inboxItem\(inboxItem)")
            switch buttonAction.actionType {
                case .deepLink:
                    break
                case .navigateToScreen:
                    break
                case .richLanding:
                    break
                case .requestForPush:
                    break
                case .dismiss:
                    break
                case .custom:
                    break
                default:
                    break
            }
        }

    }

Customising App Inbox Display

func showAppInbox() {
    // Customise the App Inbox styling using the below mentioned parameters
    let style = CastledInboxDisplayConfig()
    style.inboxViewBackgroundColor = .white
    style.navigationBarBackgroundColor = .link
    style.navigationBarTitle = "Castled Inbox"
    style.navigationBarButtonTintColor = .white
    style.loaderTintColor = .blue
    // style.hideBackButton = true
    // style.backButtonImage = UIImage(named: 'back_image')


    // Categories tab styling
    style.showCategoriesTab = true
    style.tabBarDefaultTextColor = .green
    style.tabBarSelectedTextColor = .brown
    style.tabBarDefaultBackgroundColor = .purple
    style.tabBarSelectedBackgroundColor = .lightGray
    style.tabBarIndicatorBackgroundColor = .red

    let inboxViewController = CastledInbox.sharedInstance.getInboxViewController(with: style, andDelegate: self)
    navigationController?.pushViewController(inboxViewController!, animated: true)
}

Retrieving Unread Message Count

The SDK offers multiple methods to obtain the count of unread messages, suitable for display purposes. Developers can choose from the following options based on their specific use-case:

Approach 1 : Listener Approach

CastledInbox.sharedInstance.observeUnreadCountChanges(listener: { unreadCount in
    print("Inbox unread count is \(unreadCount)")
})

Approach 2 : Direct call

CastledInbox.sharedInstance.getInboxUnreadCount()

Dismiss App Inbox

Use the method below to dismiss the App Inbox programmatically.

CastledInbox.sharedInstance.dismissInboxViewController()