In-app Chat
SDK Error Codes
On this page

Set custom push rules

2026-11-06

If a user is logged in on multiple platforms, the user can configure custom push rules to specify the platforms that can or cannot receive offline push notifications.

Prerequisites

Before you implement the custom push rule feature, make sure that the following conditions are met:

Implementation steps

Notification for offline push rule update

To receive notifications when users customize rules, please listen for the userRuleUpdated callback.

// Listen for user-defined rules
- (void)zim:(ZIM *)zim userRuleUpdated:(ZIMUserRule *)userRule{
    // Offline push rules
    userRule.offlinePushRule;
}

Set offline push rules

To support custom push rules, developers need to construct ZIMUserOfflinePushRule to specify the platforms that do not receive offline push notifications (notToReceiveOfflinePushPlatforms) when the user is online on specified platforms (onlinePlatforms).

Starting from version 3.3.0, ZIMUserOfflinePushRule adds the following fields:

FieldDescription
offlinePushEnabledMaster switch for offline push, enabled by default. When it is disabled, neither message nor call offline push notifications are delivered.
messageOfflinePushEnabledSwitch for message offline push, enabled by default. It only affects message offline push and does not affect call offline push.
callOfflinePushEnabledSwitch for call offline push, enabled by default. It only affects call offline push and does not affect message offline push.
doNotDisturbRuleDo-not-disturb time rule. While the rule is in effect, neither message nor call offline push notifications are delivered. For details, see Set the do-not-disturb time rule.

To set the above rules, call the updateUserOfflinePushRule interface.

// Construct ZIMUserOfflinePushRule
ZIMUserOfflinePushRule *offlineRule = [[ZIMUserOfflinePushRule alloc] init];
// When the user logs in on Windows, macOS, and Linux platforms.
offlineRule.onlinePlatforms = @[@(ZIMPlatformTypeWin),@(ZIMPlatformTypeMacOS),@(ZIMPlatformTypeLinux)];
// The user does not receive offline push on the iPhoneOS, iPadOS, and Android platforms.
offlineRule.notToReceiveOfflinePushPlatforms = @[@(ZIMPlatformTypeIPhoneOS),@(ZIMPlatformTypeIPadOS),@(ZIMPlatformTypeAndroid)];

// Master switch for offline push, enabled by default (supported from version 3.3.0)
offlineRule.offlinePushEnabled = YES;
// Switch for message offline push, only affects message offline push, enabled by default (supported from version 3.3.0)
offlineRule.messageOfflinePushEnabled = YES;
// Switch for call offline push, only affects call offline push, enabled by default (supported from version 3.3.0)
offlineRule.callOfflinePushEnabled = YES;

[[ZIM getInstance] updateUserOfflinePushRule:offlineRule callback:^(ZIMUserOfflinePushRule * _Nonnull offlinePushRule, ZIMError * _Nonnull errorInfo) {
}];

Set the do-not-disturb time rule

Starting from version 3.3.0, ZIMUserOfflinePushRule supports setting the do-not-disturb time rule through the doNotDisturbRule field. While the rule is in effect, neither message nor call offline push notifications are delivered.

Note

When calling the updateUserOfflinePushRule interface, the offline push rule is fully updated according to the member attributes of the passed object. To modify a single configuration item such as the do-not-disturb time rule, first call querySelfUserInfo to query the current complete offline push rule, then modify it and submit it in full, so as to avoid overwriting other existing configurations.

The fields of ZIMUserOfflinePushDoNotDisturbRule are described as follows:

FieldDescription
enabledWhether to enable the do-not-disturb rule.
startHour / startMinuteStart time of the do-not-disturb period. The hour ranges from [0, 23] and the minute ranges from [0, 59].
endHour / endMinuteEnd time of the do-not-disturb period. The hour ranges from [0, 23] and the minute ranges from [0, 59]. When the end time is earlier than the start time, the period crosses midnight, for example, from 22:00 to 08:00 the next day.
repeatModeRepeat mode:
  • None (1): no repeat, and the rule only takes effect on the day it is saved.
  • Daily (2): repeat every day.
  • Custom (3): custom repeat days, used together with customRepeatDays.
The default is Unknown (not set), in which case the SDK reports 0 to the server and the rule only takes effect on the day it is saved (no repeat).
customRepeatDaysCustom repeat days in bitmask format, where bit0 represents Monday and bit6 represents Sunday. It only takes effect when repeatMode is Custom.
onceEndTimestampWhen repeatMode is None, the UNIX timestamp (in seconds) of the end of the do-not-disturb period that takes effect only once, recorded by the server when the rule is saved. Read-only field: the value passed in when updating the rule is ignored and recalculated by the server.
timeZoneIDThe IANA time zone ID of the do-not-disturb period, for example, "Asia/Shanghai". An empty string means it is not specified, and the server calculates the period in UTC. When it is not empty, the server validates it (an invalid ID returns an error code) and calculates the period in that time zone (daylight saving time aware). To follow the device time zone, explicitly obtain and pass in the local IANA time zone ID.
// First query the current complete offline push rule
[[ZIM getInstance] querySelfUserInfo:^(ZIMSelfUserInfo * _Nonnull selfUserInfo, ZIMError * _Nonnull errorInfo) {
    if (errorInfo.code == ZIMErrorCodeSuccess) {
        ZIMUserOfflinePushRule *offlineRule = selfUserInfo.userRule.offlinePushRule;

        // Modify the do-not-disturb time rule (supported from version 3.3.0)
        ZIMUserOfflinePushDoNotDisturbRule *doNotDisturbRule = [[ZIMUserOfflinePushDoNotDisturbRule alloc] init];
        doNotDisturbRule.enabled = YES;
        // Do-not-disturb period: 22:00 every day to 08:00 the next day
        doNotDisturbRule.startHour = 22;
        doNotDisturbRule.startMinute = 0;
        doNotDisturbRule.endHour = 8;
        doNotDisturbRule.endMinute = 0;
        // Repeat every day
        doNotDisturbRule.repeatMode = ZIMUserOfflinePushDoNotDisturbRepeatModeDaily;
        // Time zone. It is recommended to explicitly pass in the local IANA time zone ID
        doNotDisturbRule.timeZoneID = @"Asia/Shanghai";
        offlineRule.doNotDisturbRule = doNotDisturbRule;

        // Fully update the offline push rule
        [[ZIM getInstance] updateUserOfflinePushRule:offlineRule callback:^(ZIMUserOfflinePushRule * _Nonnull offlinePushRule, ZIMError * _Nonnull errorInfo) {
        }];
    }
}];

Query user-defined push rules

By calling querySelfUserInfo, you can get the current user-defined offline push rules in the selfUserInfo.userRule.offlinePushRule field in the callback.

[[ZIM getInstance] querySelfUserInfo:^(ZIMSelfUserInfo * _Nonnull selfUserInfo, ZIMError * _Nonnull errorInfo) {
    selfUserInfo.userRule.offlinePushRule; // Current user-defined offline push rules
}];

Previous

Implementing Offline Push Notifications with the ZIM SDK

Next

ZIM

On this page

Back to top