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.

Displaying App Inbox content

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

Using Navigation Controller

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

func pushViewController() {
    let inboxViewController = Castled.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.

  func presentViewController() {
      let inboxViewController = Castled.sharedInstance.getInboxViewController(withUIConfigs: nil, andDelegate: self)
      self.navigationController?.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(_ action: CastledClickActionType, _ kvPairs: [AnyHashable: Any]?, _ inboxItem: CastledInboxItem)
}

Integration Steps:

  1. Ensure your view controller conforms to the CastledInboxViewControllerDelegate protocol.
  2. Implement the didSelectedInboxWith(\_:kvPairs:inboxItem:) delegate method.
    class MyViewController: CastledInboxViewControllerDelegate {
    ...
        // Implement the callback method
        func didSelectedInboxWith(_ action: CastledClickActionType, _ kvPairs: [AnyHashable: Any]?, _ inboxItem: CastledInboxItem) {
            switch action {
                case .deepLink:
                    break
                case .navigateToScreen:
                    break
                case .richLanding:
                    break
                case .requestForPush:
                    break
                case .dismiss:
                    break
                case .custom:
                    break
                default:
                    break
            }
        }

        func presentViewController() {
            // Set the delegate to the method invoked for fetching the App inbox view controller
            let inboxViewController = Castled.sharedInstance.getInboxViewController(with: nil, andDelegate: self)
            self.navigationController?.present(inboxViewController, animated: true, completion: nil)
        }
        ...
    }

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.hideCloseButton = true

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

    let inboxViewController = Castled.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

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

Approach 2 : Direct call

Castled.sharedInstance.getInboxUnreadCount()

Dismiss App Inbox

Use the method below to dismiss the App Inbox programmatically.

Castled.sharedInstance.dismissInboxViewController()