Skip to main content

About local notifications

The Chat SDK does not implement local notifications. You need to implement local notifications at the application level.

tip
  • When the app first enters the background, it remains active for a short period. The SDK continues to receive messages through its persistent connection and triggers message receive listeners. You can display local notifications when receiving these messages. See Receive messages for details.
  • After the app has been in the background for approximately 2 minutes, the system suspends the app and the SDK disconnects. New messages are delivered through the APNs push channel.

For community channels, you may need to combine the do not disturb level feature to implement fine-grained local notification control.

The SDK's do not disturb API is asynchronous and queries the database each time, which may introduce latency. If you need to read do not disturb levels from memory for faster performance, consider the following approach:

  1. Create a helper class (e.g., NCMessageNotificationHelper) with a method like checkNotifyAbilityWith: to determine if a message should display a local notification.

  2. Maintain a global NSDictionary to cache the do not disturb status for queried channels. If the cache misses, fall back to a database query and update the cache.

  3. In the message receive callback (onMessageReceived:), check the channel's do not disturb level to decide whether to show a local notification:

swift
import NexconnChatSDK
func onMessageReceived(_ event: MessageReceivedEvent) {
let message = event.message
let channel = [self getChannelForMessage:message]
if (channel.noDisturbLevel == NCChannelNoDisturbLevelDefaultLevel) {
// Show notification
} else {
// Suppress notification
}
}

Priority order for notification display logic: Message-level config > User global setting > User-specific channel setting > User-specific group > Channel type setting > Community channel default config.