Skip to main content

Local Notification

IMKit has implemented the creation and display behavior of local notifications, enabling developers to quickly build applications.

What Is Local Notification

Local notification refers to notifications created and sent directly by IMKit or the application client by calling system APIs when the app is running in the foreground or background. The IMKit SDK has built-in local notification functionality. When the app is in the background and receives a new message, IMKit will display a notification in the notification panel by default, which is the local notification.

IMKit's local notification supports the following scenarios:

  • When the app has just entered the background (still in an active background state): After the app enters the background, the SDK's persistent connection remains alive for up to 2 minutes before actively disconnecting. Within 2 minutes of entering the background, IMKit can still receive new messages (including recall command messages) through the persistent connection. Upon receiving a new message, IMKit will create and display a notification by default, i.e., the local notification.

    tip

    After the app enters an inactive background state (e.g., killed by the system), IMKit disconnects from the server. If the app has integrated APNs push services, push notifications can be received at this time. Push notifications are created and displayed directly by the system and do not fall under the local notifications described here.

  • When the app is in the foreground and no conversation UI is open (not chatting with anyone), it will play a ringtone and vibrate by default upon receiving a new message but will not display a notification.

tip

To use the SDK's default local notification reminders when the app is in the background and alive, you must implement the user/group/group alias information provider protocols and return the correct user or group information. For details, see User Information.

Set Foreground Ringtone Alerts

When the app is in the foreground, it will play a message alert sound by default. You can disable all foreground message alert sounds by setting this property to YES.

RCKitConfigCenter.message.disableMessageAlertSound = YES;

Disable Local Notification

IMKit enables local notification by default. To disable it, refer to the following:

RCKitConfigCenter.message.disableMessageNotificaiton = YES;

Customize Local Notification

Before displaying a local notification, IMKit triggers a callback method in the message reception listener. Implement the following delegate method of the message reception listener and return YES. The SDK will no longer display the default local notification for this message, allowing you to handle it yourself.

tip

If the app does not implement the user/group/group alias information provider, the IMKit SDK cannot retrieve user/group/group alias information for the message and will not trigger this callback method.

@protocol RCIMReceiveMessageDelegate <NSObject>
@optional
- (BOOL)onRCIMCustomLocalNotification:(RCMessage *)message withSenderName:(NSString *)senderName;

@end
ParameterTypeDescription
messageRCMessageThe received message
senderNameNSStringThe sender's display name