Global do not disturb
Set a global do not disturb (DND) window for the current user. During the window, the server does not send push notifications for missed messages.
- The window is defined by a start time (
HH:mm:ss) and a duration in minutes. It repeats daily until changed. - To enable all-day DND permanently, set
startTimeto00:00:00andspanMinutesto1439. - Each user can have only one active window. Setting a new one replaces the previous.
tip
Global DND has the highest priority. When active, it overrides DND settings by channel and by channel type.
If the app is running in the background, use the DND level you set here to decide whether to display local notifications.
Set the DND window
Create a NoDisturbTimeParams object and call NCEngine.setNoDisturbTime(params:completion:):
- Swift
- Objective-C
swift
import Foundation
import NexconnChatSDK
let params = NoDisturbTimeParams(startTime: "00:00:00", spanMinutes: 1439)
params.level = .muted
params.timezone = TimeZone.current.identifier
NCEngine.setNoDisturbTime(params: params) { error in
if let error {
print("Failed: \(error.localizedDescription)")
return
}
print("DND window set.")
}
Objective C
NCNoDisturbTimeParams *params = [[NCNoDisturbTimeParams alloc] initWithStartTime:@"00:00:00"
spanMinutes:1439];
params.level = NCNoDisturbTimeLevelMuted;
params.timezone = [NSTimeZone localTimeZone].name;
[NCEngine setNoDisturbTimeWithParams:params completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"DND window set.");
} else {
NSLog(@"Failed: %@", error);
}
}];
NCNoDisturbTimeParams
| Parameter | Type | Required | Description |
|---|---|---|---|
startTime | NSString | Yes | Start time in HH:mm:ss format (for example, 01:30:00) |
spanMinutes | int32_t | Yes | Duration in minutes. Range: 1 to 1439. |
level | NCNoDisturbTimeLevel | No | Notification level during the window. Default: .default. |
timezone | NSString | No | Timezone name, for example Asia/Shanghai. Uses the server default when nil. |
NCNoDisturbTimeLevel
| Enum value | Numeric value | Description |
|---|---|---|
NCNoDisturbTimeLevelDefault | 0 | Not set. Falls through to other DND settings. |
NCNoDisturbTimeLevelMention | 1 | Notify only for @mention messages (@user and @everyone). |
NCNoDisturbTimeLevelMuted | 5 | Suppress all notifications, including mentions. |
Remove the DND window
To remove the DND window, set level to .default for the full day:
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = NoDisturbTimeParams(startTime: "00:00:00", spanMinutes: 1439)
params.level = .default
NCEngine.setNoDisturbTime(params: params) { error in
if error == nil {
print("DND window cleared.")
}
}
Objective C
NCNoDisturbTimeParams *params = [[NCNoDisturbTimeParams alloc] initWithStartTime:@"00:00:00"
spanMinutes:1439];
params.level = NCNoDisturbTimeLevelDefault;
[NCEngine setNoDisturbTimeWithParams:params completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"DND window cleared.");
}
}];