logo
On this page

Set custom push rules

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:

Procedure

Notification for offline push rule update

To receive the notification for custom rule update, register the ZIMEventHandler delegate callback and listen for onUserRuleUpdated.

userRuleUpdated description

Untitled
// Listen for custom rules.
@Override
void onUserRuleUpdated(ZIM * /*zim*/, const ZIMUserRule & userRule) {
    // Offline push rules.
    userRule.offlinePushRule;
}
1
Copied!

Set offline push rules

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

To set the above rules, call the updateUserOfflinePushRule method.

Untitled
// Set offline push rules.

// Build the ZIMUserOfflinePushRule class.
zim::ZIM::ZIMUserOfflinePushRule offlineRule;

// The user is logged in to Windows, macOS, and Linux platforms.
offlineRule.onlinePlatforms = {ZIM_PLATFORM_TYPE_WIN, ZIM_PLATFORM_TYPE_MACOS, ZIM_PLATFORM_TYPE_LINUX};

// The user receives no offline push on the iPhoneOS, iPadOS, and Android platforms.
offlineRule.notToReceiveOfflinePushPlatforms = {ZIM_PLATFORM_TYPE_IPHONEOS, ZIM_PLATFORM_TYPE_IPADOS, ZIM_PLATFORM_TYPE_ANDROID};


// Call the updateUserOfflinePushRule method
zim::ZIM::ZIM.getInstance()->updateUserOfflinePushRule(offlineRule, [](const zim::ZIM::ZIMUserOfflinePushRule& updatedOfflinePushRule, const zim::ZIM::ZIMError& errorInfo) {});
1
Copied!

Query custom push rules

Call the querySelfUserInfo method to obtain custom offline push rules from the selfUserInfo.userRule.offlinePushRule field in the callback.

Untitled
zim::ZIM::ZIM.getInstance()->querySelfUserInfo([](const zim::ZIM::ZIMSelfUserInfo& selfUserInfo, const zim::ZIM::ZIMError& errorInfo) {

    selfUserInfo.userRule.offlinePushRule; // Offline push rules defined by the current user.
});
1
Copied!

Previous

Instruction

Next

ZIM