Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Message
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Send a critical alert message to iOS device users

Your app is most likely to have users from different devices that run on iOS, Android, or the web, which calls for the need to implement platform-specific code when it comes to sending a notification such as a critical alert. A critical alert is a notification that can be sent to iOS device users even when Mute or Do Not Disturb is turned on. Use a UserMessageCreateParams instance to properly notify critical alert messages to iOS device users in your app.

First, create an AppleCriticalAlertOptions instance and set it as an attribute of a UserMessageCreateParams instance. Then, pass the UserMessageCreateParams instance as an argument to a parameter in the sendUserMessage(params:completionHandler:) method. The same applies to FileMessageCreateParams and sendFileMessage(params:completionHandler:).

Note: To learn more about how to set critical alerts, see Apple critical alerts.

// Send a critical alert user message.
let userMessageParams = UserMessageCreateParams(message: MESSAGE_TEXT)
let options = AppleCriticalAlertOptions()
options.name = "name"
options.volume = 0.7    // Acceptable values for options.volume are 0 to 1.0, inclusive.
userMessageParams.appleCriticalAlertOptions = options

channel.sendUserMessage(params: userMessageParams) { userMessage, error in
    guard error == nil else {
        // Handle error.
        return 
    }
}
// Send a critical alert file message.
let fileMessageParams = FileMessageCreateParams(file: FILE)
let options = AppleCriticalAlertOptions()
options.name = "name"
options.volume = 0.7    // Acceptable values for options.volume are 0 to 1.0, inclusive.
fileMessageParams.appleCriticalAlertOptions = options

channel.sendFileMessage(params: fileMessageParams) { fileMessage, error in
    guard error == nil else {
        // Handle error.
        return 
    }
}