Skip to main content

Global Do Not Disturb

The IMLib SDK supports setting global Do Not Disturb time windows and levels for the current user.

  • This feature allows configuring a Do Not Disturb time window starting from any time point (HH:MM:SS). The configured time window will repeat daily until modified or removed. For example, if an app user wants permanent 24/7 Do Not Disturb, they can set startTime to 00:00:00 and period to 1439.
  • Each user can only set one time window - repeated configurations will overwrite previous settings.
  • For IMLib SDK versions < 5.2.2, only Do Not Disturb time windows are supported (without level configuration).
tip

During Global Do Not Disturb periods configured via IMLib SDK:

  • If the client is offline, Rong Cloud server will not send push notifications.
  • Global Do Not Disturb periods are user-level settings with the highest priority. When configured, these settings override all other Do Not Disturb configurations.

When detecting the client app has moved to background (without being suspended by the system), we recommend using IMLib SDK's Get Global Do Not Disturb API to determine whether to display local notifications, achieving true global Do Not Disturb behavior.

Configure Do Not Disturb Periods and Levels (SDK ≥ 5.2.2)

tip

Starting from IMLib SDK 5.2.2, you can configure both Do Not Disturb periods and corresponding levels simultaneously. Earlier versions (before 5.2.2) only support enabling/disabling push notifications during Do Not Disturb periods.

Configure Do Not Disturb Periods and Levels

Use the setNotificationQuietHoursLevel: method to configure message notification Do Not Disturb periods and levels. For offline messages received during Do Not Disturb periods, the server will determine whether to push notifications based on the configured level.

Method Signature

- (void)setNotificationQuietHoursLevel:(NSString *)startTime
spanMins:(int)spanMins
level:(RCPushNotificationQuietHoursLevel)level
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

Parameters

ParameterTypeDescription
startTimeNSStringStart time (second precision) in HH:MM:SS format, e.g. 01:31:17.
spanMinsintDo Not Disturb window duration in minutes. Valid range: [1-1439].
levelRCPushNotificationQuietHoursLevel
  • 1: Only notify for @mentions (both user-specific and @all). No notifications for one-to-one chats.
  • 0: Default configuration. If unset, IMLib SDK will check group-level Do Not Disturb settings and other non-user-level configurations to determine notification behavior.
  • 5: Block all notifications, including @mentions.
successBlockBlockSuccess callback
errorBlockBlockFailure callback. The status parameter contains error codes (see [RCErrorCode]).

Example Code

 [[RCChannelClient sharedChannelManager] setNotificationQuietHoursLevel:@"00:00:00"
spanMins:1439
level:(RCPushNotificationQuietHoursLevel)level
success:^() {} error:^(RCErrorCode status) {}];

Configure Do Not Disturb with Timezone Support

tip

Available in RCChannelClient since version 5.14.0.

Use the setNotificationQuietHoursWithSetting: method to configure Do Not Disturb periods and levels with timezone support via [RCNotificationQuietHoursSetting]. For offline messages received during Do Not Disturb periods, the server will determine notification behavior based on the configured level.

Method Signature

- (void)setNotificationQuietHoursWithSetting:(RCNotificationQuietHoursSetting *)setting
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

Parameters

ParameterTypeDescription
settingRCNotificationQuietHoursSettingDo Not Disturb configuration (see [RCNotificationQuietHoursSetting]).
successBlockBlockSuccess callback
errorBlockBlockFailure callback. The status parameter contains error codes (see [RCErrorCode]).

Example Code

RCNotificationQuietHoursSetting *setting = [RCNotificationQuietHoursSetting new];
setting.timezone = [NSTimeZone localTimeZone].name;
setting.startTime = @"00:00:00";
setting.spanMins = 1439;
setting.level = RCPushNotificationQuietHoursLevelMention;
[[RCChannelClient sharedChannelManager] setNotificationQuietHoursWithSetting:setting
success:^() {}
error:^(RCErrorCode status) {}];

Remove Do Not Disturb Periods and Levels

You can remove previously set Do Not Disturb configurations by setting the all-day quiet level to RCPushNotificationQuietHoursLevelDefault:

[[RCChannelClient sharedChannelManager] setNotificationQuietHoursLevel:@"00:00:00"
spanMins:1439
level:(RCPushNotificationQuietHoursLevel)level
success:^() {} error:^(RCErrorCode status) {
}];
You can also remove previously set Do Not Disturb configurations by calling the remove interface:

```objectivec
[[RCChannelClient sharedChannelManager] removeNotificationQuietHours:^{

} error:^(RCErrorCode status) {
}];


### Retrieve Do Not Disturb Periods and Levels

You can obtain Do Not Disturb time settings via the `getNotificationQuietHoursLevel:` method. When receiving messages during Do Not Disturb periods, the system determines whether push notifications are needed based on the current quiet level.


#### Interface Prototype
```objectivec


- (void)getNotificationQuietHoursLevel:(nullable void (^)(NSString *startTime, int spanMins, RCPushNotificationQuietHoursLevel level))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;


#### Parameter Description
| Parameter | Type | Description |
|:-------------|:-----|:--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| successBlock | BOOL | Success callback. `startTime` indicates the global Do Not Disturb start time (format: `HH:MM:SS`). `spanMins` indicates the duration in minutes. `level` corresponds to the `RCPushNotificationQuietHoursLevel` set during configuration. |
| errorBlock | BOOL | Failure callback. `status` contains error codes, see [RCErrorCode]. |


#### Example Code
```objectivec
[[RCChannelClient sharedChannelManager] getNotificationQuietHoursLevel:^(NSString *startTime, int spanMins, RCPushNotificationQuietHoursLevel level) {

} error:^(RCErrorCode status) {

}];


### Retrieve Do Not Disturb Periods and Levels (Timezone Supported)

:::tip
This interface is available in `RCChannelClient` starting from version 5.14.0.
:::

You can obtain Do Not Disturb time settings via the `getNotificationQuietHoursSetting:` method, where [RCNotificationQuietHoursSetting] includes timezone information. When receiving offline messages during Do Not Disturb periods, the server determines whether push notifications are needed based on the current quiet level.


#### Interface Prototype
```objectivec


- (void)getNotificationQuietHoursSetting:(nullable void (^)(RCNotificationQuietHoursSetting *setting))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;


#### Parameter Description
| Parameter | Type | Description |
|:-------------|:-----|:--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| successBlock | BOOL | Success callback. `setting` contains global Do Not Disturb configuration details, see [RCNotificationQuietHoursSetting]. |
| errorBlock | BOOL | Failure callback. `status` contains error codes, see [RCErrorCode]. |


#### Example Code
```objectivec
[[RCChannelClient sharedChannelManager] getNotificationQuietHoursSetting:^(RCNotificationQuietHoursSetting *setting) {

} error:^(RCErrorCode status) {

}];


## Configure Global Do Not Disturb Periods (< 5.2.2)

SDK versions prior to 5.2.2 only support setting Do Not Disturb periods. No message alerts will be received during global Do Not Disturb time windows.

Exception: @mentions are high-priority messages that bypass global Do Not Disturb logic. Offline @mention messages received during quiet hours will still trigger push notifications.
:::tip
Related interfaces in `RongIMLibCore` are deprecated starting from version 5.2.2.
:::


### Configure Global Do Not Disturb Periods

Use the `setNotificationQuietHours:` method to set global Do Not Disturb periods, which will suppress all remote push notifications during the specified time window.


#### Interface Prototype
```objectivec


- (void)setNotificationQuietHours:(NSString *)startTime
spanMins:(int)spanMins
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;


#### Parameter Description
| Parameter | Type | Description |
|:-------------|:---------|:----------------------------------------------------------|
| startTime | NSString | Start time in `HH:MM:SS` format (e.g., `01:31:17`). |
| spanMins | int | Duration of quiet window in minutes (valid range: 1-1439). |
| successBlock | BOOL | Success callback |
| errorBlock | BOOL | Failure callback. `status` contains error codes, see [RCErrorCode]. |


#### Example Code
```objectivec
[[RCCoreClient sharedCoreClient] setNotificationQuietHours:@"00:00:00"
spanMins:1439
success:^{}
error:^(RCErrorCode status) {
}];


### Retrieve Global Do Not Disturb Periods

Use the `getNotificationQuietHours:` method to obtain configured global Do Not Disturb settings.


#### Interface Prototype
```objectivec


- (void)getNotificationQuietHours:(nullable void (^)(NSString *startTime, int spanMins))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;


#### Parameter Description
| Parameter | Type | Description |
|:-------------|:-----|:----------------------------------------------------------------------------------------------------|
| successBlock | BOOL | Success callback. `startTime` indicates the global Do Not Disturb start time (format: `HH:MM:SS`). `spanMins` indicates the duration in minutes. |
| errorBlock | BOOL | Failure callback. `status` contains error codes, see [RCErrorCode]. |


#### Example Code
```objectivec
[[RCCoreClient sharedCoreClient] getNotificationQuietHours:^(NSString *startTime, int spanMins) {

} error:^(RCErrorCode status) {

}];


### Cancel Global Do Not Disturb Periods


You can use the `removeNotificationQuietHours:` method to remove previously set Global Do Not Disturb periods. After successful removal, push notifications will be received normally.


#### Method Signature
```objectivec


- (void)removeNotificationQuietHours:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;


#### Parameter Description
| Parameter | Type | Description |
|:-------------|:-----|:----------------------------------------|
| successBlock | BOOL | Success callback. |
| errorBlock | BOOL | Failure callback. `status` is the error code, see [RCErrorCode]. |


#### Example Code
```objectivec
[[RCCoreClient sharedCoreClient] removeNotificationQuietHours:^{

} error:^(RCErrorCode status) {

}];
<!--api links-->
[RCErrorCode]: https://doc.rongcloud.cn/apidoc/imlibcore-ios/latest/zh_CN/documentation/rongimlibcore/rcerrorcode?language=objc

[RCNotificationQuietHoursSetting]: https://doc.rongcloud.cn/apidoc/imlibcore-ios/latest/zh_CN/documentation/rongimlibcore/rcnotificationquiethourssetting?language=objc