Message Center for the Apple SDK
Message Center provides an inbox for rich HTML-based messages that users can view at their convenience, with support for custom theming and display handling.

Message Center provides an inbox for rich, HTML-based messages. Learn more about Message Center in our user guide.
Display the Message Center
Display the Message Center with a single method call:
Display message center
Airship.messageCenter.display()[UAirship.messageCenter display];This displays the Message Center as an overlay window, allowing users to view and manage their messages. When the user closes the Message Center, any changes (such as marking messages as read) are automatically synced with Airship.
To embed the Message Center directly in your app’s navigation instead of displaying it as an overlay, see Embedding the Message Center. You can also intercept display requests to handle navigation to your embedded Message Center.
Applying a Custom Theme
You can customize the appearance of the Message Center by creating a MessageCenterTheme instance and setting its properties. The theme applies globally to all Message Centers displayed in your app.
Setting the Theme Programmatically (Swift)
Setting a Message Center Theme
var theme = MessageCenterTheme()
theme.cellTitleFont = .title
theme.cellDateFont = .body
theme.cellTitleColor = .primary
theme.cellDateColor = .secondary
theme.unreadIndicatorColor = .blue
// Set the theme on the Message Center
Airship.messageCenter.theme = themeSetting the Theme from a Plist
You can also customize the theme without writing code by creating a plist file. All keys in the plist correspond to properties on the MessageCenterTheme class.
Color Format:
- Named colors: Must correspond to a named color defined in a color asset within the main bundle
- Hexadecimal colors: Use separate keys for light/dark mode (e.g.,
cellTitleColorandcellTitleColorDark)
If your app is written in Objective-C, you must use the plist file to customize your theme, as MessageCenterTheme is a Swift struct.
Save the plist as MessageCenterTheme.plist in your app bundle.
Example Theme Plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>refreshTintColor</key>
<string>#333333</string>
<key>refreshTintColorDark</key>
<string>#DDDDDD</string>
<key>iconsEnabled</key>
<true/>
<key>placeholderIcon</key>
<string>placeholderIcon</string>
<key>cellTitleFont</key>
<dict>
<key>fontName</key>
<string>ChalkboardSE-Regular</string>
<key>fontSize</key>
<integer>16</integer>
</dict>
<key>cellDateFont</key>
<dict>
<key>fontName</key>
<string>ChalkboardSE-Regular</string>
<key>fontSize</key>
<integer>14</integer>
</dict>
<key>cellColor</key>
<string>#DDDDDD</string>
<key>cellColorDark</key>
<string>#333333</string>
<key>cellTitleColor</key>
<string>#000000</string>
<key>cellTitleColorDark</key>
<string>#FFFFFF</string>
<key>cellDateColor</key>
<string>#222222</string>
<key>cellDateColorDark</key>
<string>#CCCCCC</string>
<key>cellSeparatorStyle</key>
<string>none</string>
<key>cellSeparatorColor</key>
<string>#FFFFFF</string>
<key>cellSeparatorColorDark</key>
<string>#000000</string>
<key>cellTintColor</key>
<string>#FF0000</string>
<key>cellTintColorDark</key>
<string>#00FF00</string>
<key>unreadIndicatorColor</key>
<string>#FF0000</string>
<key>unreadIndicatorColorDark</key>
<string>#FF0000</string>
<key>selectAllButtonTitleColor</key>
<string>#333333</string>
<key>selectAllButtonTitleColorDark</key>
<string>#DDDDDD</string>
<key>deleteButtonTitleColor</key>
<string>#333333</string>
<key>deleteButtonTitleColorDark</key>
<string>#DDDDDD</string>
<key>markAsReadButtonTitleColor</key>
<string>#333333</string>
<key>markAsReadButtonTitleColorDark</key>
<string>#DDDDDD</string>
<key>hideDeleteButton</key>
<true/>
<key>editButtonTitleColor</key>
<string>#333333</string>
<key>editButtonTitleColorDark</key>
<string>#DDDDDD</string>
<key>cancelButtonTitleColor</key>
<string>#333333</string>
<key>cancelButtonTitleColorDark</key>
<string>#DDDDDD</string>
<key>backButtonColor</key>
<string>#333333</string>
<key>backButtonColorDark</key>
<string>#DDDDDD</string>
<key>navigationBarTitle</key>
<string>Nav Bar Title</string>
</dict>
</plist>Working with Messages
The Message Center provides methods to fetch, mark as read, and delete messages programmatically.
Fetch Messages
Retrieve messages from the inbox:
Fetch messages
let messages = await Airship.messageCenter.inbox.messages[UAirship.messageCenter.inbox getMessagesWithCompletionHandler:^(NSArray<UAMessageCenterMessage *> *messages) {
// Handle messages
}];Listen for Message Updates
Subscribe to message updates using Combine publishers:
Listen for message updates
Airship.messageCenter.inbox.messagePublisher
.receive(on: RunLoop.main)
.sink(receiveValue: { messages in
// Update your UI with the new messages
self.messages = messages
})
.store(in: &self.subscriptions)// Not available in Objective-C. Use KVO or polling instead.Listen for Unread Count Changes
Subscribe to unread count updates:
Listen for unread count
Airship.messageCenter.inbox.unreadCountPublisher
.receive(on: RunLoop.main)
.sink { unreadCount in
// Update badge or UI
self.unreadCount = unreadCount
}
.store(in: &self.subscriptions)// Not available in Objective-C. Use KVO or polling instead.Refresh Messages
Manually refresh the message list from the server:
Refresh messages
let refreshed = await Airship.messageCenter.inbox.refreshMessages()[UAirship.messageCenter.inbox refreshMessagesWithCompletionHandler:^(BOOL result) {
// Handle result
}];Mark Messages as Read
Mark one or more messages as read:
Mark message read
await Airship.messageCenter.inbox.markRead(messageIDs: [messageID])[UAirship.messageCenter.inbox markReadWithMessageIDs:@[messageID] completionHandler:^{
// Marked read
}];Delete Messages
Delete one or more messages:
Delete message
await Airship.messageCenter.inbox.delete(messageIDs: [messageID])[UAirship.messageCenter.inbox deleteWithMessageIDs:@[messageID] completionHandler:^{
// Deleted
}];Filter Messages by Named User
By default, Message Center displays all messages sent to the device’s channel. If multiple users log into your app on the same device, they’ll all see the same messages.
To filter messages by named user, set up filtering in your custom Message Center implementation. See Message Center Filtering in the Embedding guide.
When creating Message Center messages, include a custom key with named_user_id as the key and the user’s actual ID as the value:
- For the API: Use the
extraobject in the Message Center object. - In the dashboard: See Add custom keys in the Message Center content guide.
Filtering Behavior
With named user filtering enabled:
- If you target
User Ain a message while they are logged in, the message appears in their inbox. - If you target
User Bin a message while they are logged in, the message appears in their inbox. - If you target
User AorUser Bwhile the other is logged in, the message does not appear. - If you target
User AorUser Bwhile neither is logged in, the message does not appear.
Categories