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:
- Multi-device login is implemented. For more information, see Multi-device login.
Procedure
Notification for offline push rule update
To receive the notification for custom rule update, override the ZIMEventHandler > onUserRuleUpdated method.
// Listen for the user rule change.
ZIMEventHandler.onUserRuleUpdated = (ZIM zim, ZIMUserRule userRule){
// get the offline push rule
userRule.offlinePushRule;
};
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.
// Set the offline push rules.
try{
ZIMUserOfflinePushRule rule = ZIMUserOfflinePushRule();
// When the user logs in on Windows, macOS, and Linux.
rule.onlinePlatforms = [ZIMPlatformType.win,ZIMPlatformType.macOS, ZIMPlatformType.linux];
// The user does not receive offline push on the iPhoneOS, iPadOS, and Android.
rule.notToReceiveOfflinePushPlatforms = [ZIMPlatformType.iPhoneOS, ZIMPlatformType.iPadOS, ZIMPlatformType.android];
ZIMUserOfflinePushRuleUpdatedResult result = await ZIM.getInstance()!.updateUserOfflinePushRule(rule);
} on PlatformException catch (onError) {
onError.code;
onError.message;
}
Query custom push rules
Call the querySelfUserInfo method to obtain custom offline push rules from the selfUserInfo.userRule.offlinePushRule
field in the callback.
// Query push rules defined by the user
try{
ZIMSelfUserInfoQueriedResult result = await ZIM.getInstance()!.querySelfUserInfo();
result.selfUserInfo.userFullInfo; // User information
result.selfUserInfo.userRule.offlinePushRule; // Offline push rules defined by the user
} on PlatformException catch (onError) {
onError.code;
onError.message;
}