Implement Inbox Messaging on iOS
The MobilePush iOS SDK provides convenience methods for refreshing the inbox and managing messages, including retrieving, reading, and deleting them. For more information on these methods, see the InboxMessages Method Reference.
To display Inbox Only
messages sent from Marketing Cloud Engagement in your app, use the UITableView
data source provided by the SDK in a UIViewController
. The UIViewController
serves as an inbox in your app to display these messages. The SDK automatically populates the UITableView
data source with new messages after they’re downloaded.
You can manage row selection in your table view using the SDK's basic UITableView
delegate. If your app requires custom behavior, you can implement your own UITableView
delegate.
The following example demonstrates a basic inbox implementation using the SDK as the data source and delegate.
For additional control, presentation, and usability, implement your own data source and delegate using the methods offered by the SDK.
The SDK offers the following convenience methods:
Each of these methods return returns an array of dictionaries (for example, [[String: AnyObject]]
), where each dictionary represents a message.
The following table lists the public properties within the dictionary that the consuming application can use.
Key | Value |
---|---|
id | String? |
alert | String? |
subject | String? |
startDateUtc | Date? |
endDateUtc | Date? |
custom | String? |
name | String? |
title | String? |
url | String? |
deleted | Boolean |
read | Boolean |
sound | String? |
subtitle | String? |
The remaining properties within the dictionary (for example, contentType
, messageDeleted
, messageHash
, requestId
, statusDirty
) are used internally by the SDK. It isn’t recommended to use these properties within a consuming application, as they’re subject to change.
The Alert + Inbox feature is designed to enable users to tap on an inbox push notification and get redirected to the corresponding inbox message. The inbox data is added to the push notification payload. However, due to Apple's payload size restrictions, all inbox fields can't be added to the push payload. Nevertheless, users are still redirected to the message without issues, and all fields become available when they return to the inbox.
Initially, the following fields aren't available in the Alert + Inbox Message dictionary:
sendDateUtc
startDateUtc
endDateUtc
subject
statusDirty
To automatically mark an inbox message as read when a user taps on an inbox push notification, enable or disable the setMarkMessageReadOnInboxNotificationOpen
feature in the PushConfigBuilder
.
To sort inbox messages in your custom inbox implementation, use the value of sendDateUtc
from the inbox message returned by getAllMessages
and other getters.
To sort your UITableView
data source array of inbox messages, use an NSSortDescriptor
for the key sendDateUtc
. Sort your data source array with this descriptor, and then reload your UITableView
.
When the application receives an Alert + Inbox notification while it's in the foreground, it's recommended to call the refreshMessages method to fetch the latest inbox messages. Doing so ensures the UI stays updated with the most recent content. For more information, review the sample implementation in the iO LearningApp.