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.
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, register the ZIMEventHandler delegate callback and listen for userRuleUpdated.
// Listen for custom rules.
- (void)zim:(ZIM *)zim userRuleUpdated:(ZIMUserRule *)userRule{
// Offline push rules.
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 offline push rules.
// Build the ZIMUserOfflinePushRule class.
ZIMUserOfflinePushRule *offlineRule = [[ZIMUserOfflinePushRule alloc] init];
// The user is logged in to Windows, macOS, and Linux platforms.
offlineRule.onlinePlatforms = @[@(ZIMPlatformTypeWin),@(ZIMPlatformTypeMacOS),@(ZIMPlatformTypeLinux)];
// The user receives no offline push on the iPhoneOS, iPadOS, and Android platforms.
offlineRule.notToReceiveOfflinePushPlatforms = @[@(ZIMPlatformTypeIPhoneOS),@(ZIMPlatformTypeIPadOS),@(ZIMPlatformTypeAndroid)];
[[ZIM getInstance] updateUserOfflinePushRule:offlineRule callback:^(ZIMUserOfflinePushRule * _Nonnull offlinePushRule, ZIMError * _Nonnull errorInfo) {
}];
Query custom push rules
Call the querySelfUserInfo method to obtain custom offline push rules from the selfUserInfo.userRule.offlinePushRule
field in the callback.
[[ZIM getInstance] querySelfUserInfo:^(ZIMSelfUserInfo * _Nonnull selfUserInfo, ZIMError * _Nonnull errorInfo) {
selfUserInfo.userRule.offlinePushRule; // Offline push rules specified by the user.
}];