# 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 for the Apple SDK](https://www.airship.com/docs/images/message-center-apple.webp)

Message Center provides an inbox for rich, HTML-based messages. Learn more about Message Center in our [feature guide](https://www.airship.com/docs/guides/features/messaging/message-center/).

## Display the Message Center

Display the Message Center with a single method call:


#### Swift


```swift
Airship.messageCenter.display()
```



#### Objective-C


```objc
[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.

> **Note:** To embed the Message Center directly in your app's navigation instead of displaying it as an overlay, see [Embedding the Message Center](https://www.airship.com/docs/developer/sdk-integration/apple/message-center/embedding/). You can also [intercept display requests](https://www.airship.com/docs/developer/sdk-integration/apple/message-center/embedding/#handling-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)


#### Swift



```swift
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 = theme
```




### Setting 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., `cellTitleColor` and `cellTitleColorDark`)

> **Note:** 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

**MessageCenterTheme.plist**


```xml
<?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:


#### Swift


```swift
let messages = await Airship.messageCenter.inbox.messages
```



#### Objective-C


```objc
[UAirship.messageCenter.inbox getMessagesWithCompletionHandler:^(NSArray<UAMessageCenterMessage *> *messages) {
    // Handle messages
}];
```




### Listen for Message Updates

Subscribe to message updates using Combine publishers:


#### Swift


```swift
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)
```



#### Objective-C


```objc
// Not available in Objective-C. Use KVO or polling instead.
```




### Listen for Unread Count Changes

Subscribe to unread count updates:


#### Swift


```swift
Airship.messageCenter.inbox.unreadCountPublisher
    .receive(on: RunLoop.main)
    .sink { unreadCount in
        // Update badge or UI
        self.unreadCount = unreadCount
    }
    .store(in: &self.subscriptions)
```



#### Objective-C


```objc
// Not available in Objective-C. Use KVO or polling instead.
```




### Refresh Messages

Manually refresh the message list from the server:


#### Swift


```swift
let refreshed = await Airship.messageCenter.inbox.refreshMessages()
```



#### Objective-C


```objc
[UAirship.messageCenter.inbox refreshMessagesWithCompletionHandler:^(BOOL result) {
    // Handle result
}];
```




### Mark Messages as Read

Mark one or more messages as read:


#### Swift


```swift
await Airship.messageCenter.inbox.markRead(messageIDs: [messageID])
```



#### Objective-C


```objc
[UAirship.messageCenter.inbox markReadWithMessageIDs:@[messageID] completionHandler:^{
    // Marked read
}];
```




### Delete Messages

Delete one or more messages:


#### Swift


```swift
await Airship.messageCenter.inbox.delete(messageIDs: [messageID])
```



#### Objective-C


```objc
[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](https://www.airship.com/docs/developer/sdk-integration/apple/message-center/embedding/#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 `extra` object in the [Message Center object](https://www.airship.com/docs/developer/rest-api/ua/schemas/push/#messageobject).
- **In the dashboard**: See [Add custom keys](https://www.airship.com/docs/guides/messaging/messages/content/app/message-center/#add-custom-keys) in the Message Center content guide.

### Filtering Behavior

With named user filtering enabled:

- If you target `User A` in a message while they are logged in, the message appears in their inbox.
- If you target `User B` in a message while they are logged in, the message appears in their inbox.
- If you target `User A` or `User B` while the other is logged in, the message does not appear.
- If you target `User A` or `User B` while neither is logged in, the message does not appear.
