Skip to main content

Local notifications

Chat UI provides built-in local notification creation and display behavior to help developers quickly implement application features.

What are local notifications

Local notifications are system notifications created and sent directly by Chat UI or the client application when the app is running in the foreground or background. The Chat UI SDK includes built-in local notification functionality - when the app receives new messages in the background, Chat UI displays notifications in the notification panel by default.

Chat UI local notifications support these scenarios:

  • When the app just entered background (still active in background): After entering background, the SDK's persistent connection remains active for up to 2 minutes before disconnecting. During this 2-minute window, Chat UI can still receive new messages through the persistent connection. Upon receiving messages, Chat UI creates and displays notifications by default.

    tip

    After the app becomes inactive in background (e.g. terminated by system), Chat UI disconnects from the server. If the app has APNs push service integrated, it can receive push notifications at this stage. Push notifications are created and displayed directly by the system and are not considered local notifications as described here.

  • When the app is in foreground with no channel page open (not actively chatting), new messages trigger sound and vibration alerts by default but don't show notifications.

tip

To use the SDK's default local notifications when the app is active in background, you must implement the user/group/group card information provider protocols and return correct user or group information. See User information.

Configure foreground sound alerts

When the app is in foreground, message alert sounds play by default. Set this property to YES to disable all foreground message sounds.

Objective C
NCChatUIConfigCenter.message.disableMessageAlertSound = YES;

Disable local notifications

Chat UI enables local notifications by default. To disable them:

Objective C
NCChatUIConfigCenter.message.disableMessageNotificaiton = YES;

Customize local notifications

Before displaying a local notification, Chat UI triggers the message receiver listener callback. Implement the following delegate method and return YES to suppress the default local notification - you can then handle the notification yourself.

tip

If the app doesn't implement user/group/group card information providers, the Chat UI SDK cannot retrieve message sender information and won't trigger this callback.

Objective C
@protocol NCChatUIMessagePolicyDelegate <NSObject>
@optional
- (BOOL)shouldSuppressLocalNotificationForMessage:(NCMessage *)message senderName:(NSString *)senderName;

@end
ParameterTypeDescription
messageNCMessageReceived message
senderNameNSStringSender's display name