系统设置

更新时间: 2024/04/18 18:11:00

NetEase IM SDK(以下简称 NIM SDK)提供系统设置相关功能,支持设置单聊/群聊消息免打扰、获取会话消息的免打扰状态等。

本文介绍系统设置相关 API。

支持平台

Android iOS macOS/Windows Web/uni-app/小程序

API 概览

系统设置监听

Android/iOS/macOS/Windows
API 描述 起始版本
addSettingListener 注册系统设置相关监听器 v10.2.0
removeSettingListener 移除系统设置相关监听器 v10.2.0
Web/uni-app/小程序
API 描述 起始版本
on("EventName") 注册系统设置相关监听 v10.2.0
off("EventName") 取消注册系统设置相关监听 v10.2.0

系统设置操作

API 描述 起始版本
setP2PMessageMuteMode 设置单聊消息免打扰模式 v10.2.0
getP2PMessageMuteMode 获取单聊消息免打扰模式 v10.2.0
getP2PMessageMuteList 获取开启单聊消息免打扰的用户列表 v10.2.0
setTeamMessageMuteMode 设置群消息免打扰模式 v10.2.0
getTeamMessageMuteMode 获取群消息免打扰模式 v10.2.0
getConversationMuteStatus 获取会话消息免打扰状态 v10.2.0
setAppBackground 设置应用前后台状态(仅 Web 端) v10.2.0
setPushMobileOnDesktopOnline 设置当桌面端在线时,移动端是否需要推送 v10.2.0
setDndConfig 设置推送全局免打扰(仅移动端端) v10.2.0
setOfflinePushConfig 设置离线推送配置信息(仅 Web 端) v10.2.0
getDndConfig 获取推送免打扰配置信息(仅移动端) v10.2.4

接口类

V2NIMSettingService 类提供系统设置相关接口,包括设置单聊/群聊消息免打扰模式、获取单聊/群聊消息免打扰模式、获取单聊消息免打扰列表、获取会话消息的免打扰状态等接口。

addSettingListener

接口描述

注册系统设置相关监听器。

注册成功后,当事件发生时,SDK 会返回对应的回调。

  • 建议在初始化后调用该方法。

  • 全局只需注册一次。

  • 该方法为同步。

参数说明

Android
javavoid addSettingListener(V2NIMSettingListener listener);
参数名称 类型 是否必填 默认值 描述
listener V2NIMSettingListener - 系统设置相关监听器
iOS
objective-c- (void)addSettingListener:(id<V2NIMSettingListener>)listener;
参数名称 类型 是否必填 默认值 描述
listener id<V2NIMSettingListener> - 系统设置相关监听器
macOS/Windows
cppvirtual void addSettingListener(V2NIMSettingListener listener) = 0;
参数名称 类型 是否必填 默认值 描述
listener V2NIMSettingListener - 系统设置相关监听器

示例代码

Android
javaNIMClient.getService(V2NIMSettingService.class).addSettingListener(new V2NIMSettingListener() {
    @Override
    public void onTeamMessageMuteModeChanged(String teamId, V2NIMTeamType teamType, V2NIMTeamMessageMuteMode muteMode) {

    }

    @Override
    public void onP2PMessageMuteModeChanged(String accountId, V2NIMP2PMessageMuteMode muteMode) {

    }
});
iOS
objective-c[[[NIMSDK sharedSDK] v2SettingService] addSettingListener:self];
macOS/Windows
cppV2NIMTeamListener listener;
listener.onTeamMessageMuteModeChanged = [](std::string teamId, V2NIMTeamType teamType, V2NIMTeamMessageMuteMode muteMode) {
    // handle team message mute mode changed
};
listener.onP2PMessageMuteModeChanged = [](std::string accountId, V2NIMP2PMessageMuteMode muteMode) {
    // handle p2p message mute mode changed
};
settingService.addSettingListener(listener);

返回值

removeSettingListener

接口描述

移除系统设置相关监听器。

该方法为同步。

参数说明

Android
javavoid removeSettingListener(V2NIMSettingListener listener);
参数名称 类型 是否必填 默认值 描述
listener V2NIMSettingListener - 系统设置相关监听器
iOS
objective-c- (void)removeSettingListener:(id<V2NIMSettingListener>)listener;
参数名称 类型 是否必填 默认值 描述
listener id<V2NIMSettingListener> - 系统设置相关监听器
macOS/Windows
cpp virtual void removeSettingListener(V2NIMSettingListener listener) = 0; 
参数名称 类型 是否必填 默认值 描述
listener V2NIMSettingListener - 系统设置相关监听器

示例代码

Android
javaNIMClient.getService(V2NIMSettingService.class).removeSettingListener(listener);
iOS
objective-c[[[NIMSDK sharedSDK] v2SettingService] removeSettingListener:self];
macOS/Windows
cppV2NIMTeamListener listener;
// ...
settingService.removeSettingListener(listener);

返回值

on("EventName")

支持平台

Android iOS macOS/Windows Web
× × ×

接口描述

注册系统设置相关监听。

注册成功后,当事件发生时,SDK 会返回对应的回调。

  • 建议在初始化后调用该方法。

  • 全局只需注册一次。

  • 该方法为同步。

参数说明

typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
  /**
   * 继承自 EventEmitter3 的监听事件方法。
   */
  on<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
  /**
   * 继承自 EventEmitter3 的监听事件方法。
   */
  once<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
}
参数名称 类型 是否必填 默认值 描述
eventName T - 事件名称:
  • onTeamMessageMuteModeChanged:群消息免打扰模式变更回调,包括群组 ID、群组类型、群消息免打扰模式。
  • onP2PMessageMuteModeChanged:单聊(点对点)消息免打扰模式变更回调,包括聊天对象账号、单聊消息免打扰模式。
  • fn function - 监听事件的回调函数。当事件触发时,会调用该函数进行处理。

    示例代码

    typescriptnim.V2NIMSettingService.on("onTeamMessageMuteModeChanged", function (teamId: string, teamType: V2NIMTeamType, muteMode: V2NIMTeamMessageMuteMode)
    nim.V2NIMSettingService.on("onP2PMessageMuteModeChanged", function (accountId: string, muteMode: V2NIMP2PMessageMuteMode)
    

    返回值

    off("EventName")

    支持平台

    Android iOS macOS/Windows Web
    × × ×

    接口描述

    取消注册系统设置相关监听。

    该方法为同步。

    参数说明

    typescriptexport interface NIMEBaseServiceInterface<I extends NIMEBaseListener> {
      /**
       * 继承自 EventEmitter3 的取消监听方法。
       */
      off<T extends keyof I>(eventName: T, fn: (...args: I[T]) => void): void;
      /**
       * 继承自 EventEmitter3 的移除事件方法。
       */
      removeAllListeners<T extends keyof I>(eventName?: T): void;
    }
    
    参数名称 类型 是否必填 默认值 描述
    eventName T - 事件名称: 事件名称:
  • onTeamMessageMuteModeChanged:群消息免打扰模式变更回调,包括群组 ID、群组类型、群消息免打扰模式。
  • onP2PMessageMuteModeChanged:单聊(点对点)消息免打扰模式变更回调,包括聊天对象账号、单聊消息免打扰模式。
  • fn function - 监听事件的回调函数。当事件触发时,会调用该函数进行处理。

    示例代码

    typescriptnim.V2NIMSettingService.off("onTeamMessageMuteModeChanged", function (teamId: string, teamType: V2NIMTeamType, muteMode: V2NIMTeamMessageMuteMode)
    nim.V2NIMSettingService.off("onP2PMessageMuteModeChanged", function (accountId: string, muteMode: V2NIMP2PMessageMuteMode)
    

    返回值

    setP2PMessageMuteMode

    接口描述

    设置单聊(点对点)消息免打扰模式。

    本地端或多端同步设置成功后,SDK 会返回单聊消息免打扰模式变更回调 onP2PMessageMuteModeChanged,并触发会话变更。

    参数说明

    Android
    javavoid setP2PMessageMuteMode(String accountId, V2NIMP2PMessageMuteMode muteMode, V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
    
    参数名称 类型 是否必填 默认值 描述
    accountId String - 聊天对象用户账号,不可为空,否则返回 191004 参数错误。
    muteMode V2NIMP2PMessageMuteMode - 消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    iOS
    objective-c- (void)setP2PMessageMuteMode:(NSString *)accountId
                         muteMode:(V2NIMP2PMessageMuteMode)muteMode
                          success:(nullable V2NIMSuccessCallback)success
                          failure:(nullable V2NIMFailureCallback)failure;
    
    参数名称 类型 是否必填 默认值 描述
    accountId NSString * - 聊天对象用户账号,不可为空,否则返回 191004 参数错误。
    muteMode V2NIMP2PMessageMuteMode - 消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    macOS/Windows
    cppvirtual void setP2PMessageMuteMode(std::string accountId,
                                       V2NIMP2PMessageMuteMode muteMode,
                                       V2NIMSuccessCallback<void> success,
                                       V2NIMFailureCallback failure) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    accountId std::string - 聊天对象用户账号,不可为空,否则返回 191004 参数错误。
    muteMode V2NIMP2PMessageMuteMode - 消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    Web/uni-app/小程序
    typescriptsetP2PMessageMuteMode(accountId: string, muteMode: V2NIMP2PMessageMuteMode): Promise<void>
    
    参数名称 类型 是否必填 默认值 描述
    accountId string - 聊天对象用户账号,不可为空,否则返回 191004 参数错误。
    muteMode V2NIMP2PMessageMuteMode - 消息免打扰模式:免打扰开启或免打扰关闭

    示例代码

    Android
    javaNIMClient.getService(V2NIMSettingService.class).setP2PMessageMuteMode(accountId, muteMode,
    new V2NIMSuccessCallback<Void>() {
        @Override
        public void onSuccess(Void unused) {
    
        }
    },
    new V2NIMFailureCallback() {
        @Override
        public void onFailure(V2NIMError error) {
            
        }
    });
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] setP2PMessageMuteMode:@"accountId" muteMode:V2NIM_P2P_MESSAGE_MUTE_MODE_OFF success:^{
            // 成功回调
        } failure:^(V2NIMError * _Nonnull error) {
            // 失败回调
        }];
    
    macOS/Windows
    cppsettingService.setP2PMessageMuteMode(
        "accountId",
        V2NIM_P2P_MESSAGE_MUTE_MODE_ON,
        []() {
            // set p2p mute mode succeeded
        },
        [](V2NIMError error) {
            // set p2p mute mode failed, handle error
        });
    
    Web/uni-app/小程序
    typescriptnim.V2NIMSettingService.setP2PMessageMuteMode('accountId', 1)
    

    返回值

    Android/iOS/macOS/Windows

    无返回值

    Web/uni-app/小程序

    Promise<void>

    相关回调

    Android/iOS/macOS/Windows
    • 请求成功,返回 V2NIMSuccessCallback 回调;设置成功,返回 onP2PMessageMuteModeChanged 回调。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含免打扰相关错误码。
    Web/uni-app/小程序

    设置成功,返回 onP2PMessageMuteModeChanged 回调。

    getP2PMessageMuteMode

    接口描述

    获取单聊(点对点)消息免打扰模式。

    该方法为同步。

    参数说明

    Android
    javaV2NIMP2PMessageMuteMode getP2PMessageMuteMode(String accountId);
    
    参数名称 类型 是否必填 默认值 描述
    accountId String - 聊天对象用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。
    iOS
    objective-c- (V2NIMP2PMessageMuteMode)getP2PMessageMuteMode:(NSString *)accountId;
    
    参数名称 类型 是否必填 默认值 描述
    accountId NSString * - 聊天对象用户账号,不如果为空、不合法、不存在,则返回 191004 参数错误。
    macOS/Windows
    cppvirtual V2NIMP2PMessageMuteMode getP2PMessageMuteMode(nstd::string accountId) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    accountId nstd::string - 聊天对象用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。
    Web/uni-app/小程序
    typescriptgetP2PMessageMuteMode(accountId: string): V2NIMP2PMessageMuteMode
    
    参数名称 类型 是否必填 默认值 描述
    accountId string - 聊天对象用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。

    示例代码

    Android
    javaV2NIMP2PMessageMuteMode muteMode = NIMClient.getService(V2NIMSettingService.class).getP2PMessageMuteMode(accountId);
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] getP2PMessageMuteMode:@"accountId"];
    
    macOS/Windows
    cppauto muteMode = settingService.getP2PMessageMuteMode("accountId");
    
    Web/uni-app/小程序
    typescriptconst mode = nim.V2NIMSettingService.getP2PMessageMuteMode('accountId')
    

    返回值

    Android/iOS/macOS/Windows

    V2NIMP2PMessageMuteMode 单聊(点对点)消息免打扰模式

    Web/uni-app/小程序

    相关回调

    getP2PMessageMuteList

    接口描述

    获取开启单聊(点对点)消息免打扰的用户列表。

    参数说明

    Android
    javavoid getP2PMessageMuteList(V2NIMSuccessCallback<List<String>> success, V2NIMFailureCallback failure);
    
    参数名称 类型 是否必填 默认值 描述
    success V2NIMSuccessCallback - 获取成功回调,返回 accountId 列表。
    failure V2NIMFailureCallback - 获取失败回调,返回错误码
    iOS
    objective-c- (void)getP2PMessageMuteList:(nullable V2NIMGetMuteListSuccess)success
                          failure:(nullable V2NIMFailureCallback)failure;
    
    参数名称 类型 是否必填 默认值 描述
    success V2NIMGetMuteListSuccess - 获取成功回调,返回 accountId 列表,可自定义设置。
    failure V2NIMFailureCallback - 获取失败回调,返回错误码
    macOS/Windows
    cppvirtual void getP2PMessageMuteList(V2NIMSuccessCallback<nstd::vector<nstd::string>> success, V2NIMFailureCallback failure) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    success V2NIMSuccessCallback - 获取成功回调,返回 accountId 列表。
    failure V2NIMFailureCallback - 获取失败回调,返回错误码
    Web/uni-app/小程序
    typescriptgetP2PMessageMuteList(): Promise<Array<string>>
    
    参数名称 类型 是否必填 默认值 描述
    success V2NIMSuccessCallback - 获取成功回调,返回 accountId 列表。
    failure V2NIMFailureCallback - 获取失败回调,返回错误码

    示例代码

    Android
    javaNIMClient.getService(V2NIMSettingService.class).getP2PMessageMuteList(
        new V2NIMSuccessCallback<List<String>>() {
            @Override
            public void onSuccess(List<String> strings) {
    
            }
        },
        new V2NIMFailureCallback() {
            @Override
            public void onFailure(V2NIMError error) {
    
            }
        }
    );
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] getP2PMessageMuteList:^(NSArray<NSString *> * _Nonnull result) {
        // 成功回调
    } failure:^(V2NIMError * _Nonnull error) {
        // 失败回调
    }];
    
    macOS/Windows
    cppsettingService.getP2PMessageMuteList(
        [](nstd::vector<nstd::string> muteList) {
            // get p2p mute list succeeded, handle mute list
        },
        [](V2NIMError error) {
            // get p2p mute list failed, handle error
        });
    
    Web/uni-app/小程序
    typescriptconst mutedList = await nim.V2NIMSettingService.getP2PMessageMuteList()
    

    返回值

    Android/iOS/macOS/Windows

    无返回值

    Web/uni-app/小程序

    Promise<Array>

    相关回调

    Android/iOS/macOS/Windows
    • 请求成功,返回 V2NIMSuccessCallback 回调,包含 accountId 列表。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含免打扰相关错误码。
    Web/uni-app/小程序

    setTeamMessageMuteMode

    接口描述

    设置群聊消息免打扰模式。

    本地端或多端同步设置成功后,SDK 会返回群聊消息免打扰模式变更回调 onTeamMessageMuteModeChanged,并触发会话变更。

    参数说明

    Android
    javavoid setTeamMessageMuteMode(String teamId, V2NIMTeamType teamType, V2NIMTeamMessageMuteMode muteMode, V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
    
    参数名称 类型 是否必填 默认值 描述
    teamId String - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    muteMode V2NIMTeamMessageMuteMode - 群消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    iOS
    objective-c- (void)setTeamMessageMuteMode:(NSString *)teamId
                         teamType:(V2NIMTeamType)teamType
                         muteMode:(V2NIMTeamMessageMuteMode)muteMode
                          success:(nullable V2NIMSuccessCallback)success
                          failure:(nullable V2NIMFailureCallback)failure;
    
    参数名称 类型 是否必填 默认值 描述
    teamId NSString * - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    muteMode V2NIMTeamMessageMuteMode - 群消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    macOS/Windows
    cppvirtual void setTeamMessageMuteMode(std::string teamId, V2NIMTeamType teamType, V2NIMTeamMessageMuteMode muteMode, V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    teamId std::string - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    muteMode V2NIMTeamMessageMuteMode - 群消息免打扰模式:免打扰开启或免打扰关闭
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    Web/uni-app/小程序
    typescriptsetTeamMessageMuteMode(teamId: string, teamType: V2NIMTeamType, muteMode: V2NIMTeamMessageMuteMode): Promise<void>
    
    参数名称 类型 是否必填 默认值 描述
    teamId string - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    muteMode V2NIMTeamMessageMuteMode - 群消息免打扰模式:免打扰开启或免打扰关闭

    示例代码

    Android
    javaNIMClient.getService(V2NIMSettingService.class).setTeamMessageMuteMode(teamId, teamType, muteMode,
    new V2NIMSuccessCallback<Void>() {
        @Override
        public void onSuccess(Void unused) {
        // success
        }
    },
    new V2NIMFailureCallback() {
        @Override
        public void onFailure(V2NIMError error) {
        // failed, handle error
        }
    });
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] setTeamMessageMuteMode:@"teamId" teamType:V2NIM_TEAM_TYPE_INVALID muteMode:V2NIM_TEAM_MESSAGE_MUTE_MODE_OFF success:^{
        // 成功回调
    } failure:^(V2NIMError * _Nonnull error) {
        // 失败回调
    }];
    
    macOS/Windows
    cppsettingService.setTeamMessageMuteMode(
        "teamId",
        V2NIM_TEAM_TYPE_NORMAL,
        V2NIM_TEAM_MESSAGE_MUTE_MODE_ON,
        []() {
            // set team mute mode succeeded
        },
        [](V2NIMError error) {
            // set team mute mode failed, handle error
        }
    );
    
    Web/uni-app/小程序
    typescriptnim.V2NIMSettingService.setTeamMessageMuteMode('teamId', 1, 1)
    

    返回值

    Android/iOS/macOS/Windows

    无返回值

    Web/uni-app/小程序

    Promise<void>

    相关回调

    Android/iOS/macOS/Windows
    • 请求成功,返回 V2NIMSuccessCallback 回调;设置成功,返回 onTeamMessageMuteModeChanged 回调。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含免打扰相关错误码。
    Web/uni-app/小程序

    设置成功,返回 onTeamMessageMuteModeChanged 回调。

    getTeamMessageMuteMode

    接口描述

    获取群聊消息免打扰模式。

    该方法为同步。

    参数说明

    Android
    javaV2NIMTeamMessageMuteMode getTeamMessageMuteMode(String teamId, V2NIMTeamType teamType);
    
    参数名称 类型 是否必填 默认值 描述
    teamId String - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    iOS
    objective-c- (V2NIMTeamMessageMuteMode)getTeamMessageMuteMode:(NSString *)teamId
                                              teamType:(V2NIMTeamType)teamType;
    
    参数名称 类型 是否必填 默认值 描述
    teamId NSString * - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    macOS/Windows
    cppvirtual V2NIMTeamMessageMuteMode getTeamMessageMuteMode(nstd::string teamId, V2NIMTeamType teamType) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    teamId nstd::string - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。
    Web/uni-app/小程序
    typescriptgetTeamMessageMuteMode(teamId: string, teamType: V2NIMTeamType): V2NIMTeamMessageMuteMode
    
    参数名称 类型 是否必填 默认值 描述
    teamId string - 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType V2NIMTeamType - 群组类型,包括高级群和超大群。

    示例代码

    Android
    javaV2NIMTeamMessageMuteMode muteMode = NIMClient.getService(V2NIMSettingService.class).getTeamMessageMuteMode(teamId, teamType);
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] getTeamMessageMuteMode:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL];
    
    macOS/Windows
    cppauto muteMode = settingService.getTeamMessageMuteMode("teamId", V2NIM_TEAM_TYPE_NORMAL);
    
    Web/uni-app/小程序
    typescriptconst muteMode = nim.V2NIMSettingService.getTeamMessageMuteMode('teamId', 1)
    

    返回值

    Android/iOS/macOS/Windows

    V2NIMTeamMessageMuteMode 群聊消息免打扰模式

    Web/uni-app/小程序

    相关回调

    getConversationMuteStatus

    接口描述

    获取会话消息免打扰状态。

    • 该方法为同步。
    • 如果该方法返回值不满足界面显示需求,可以调用 getP2PMessageMuteModegetTeamMessageMuteMode 方法获取单聊或群聊消息的具体免打扰模式。

    参数说明

    Android
    javaboolean getConversationMuteStatus(String conversationId);
    
    参数名称 类型 是否必填 默认值 描述
    conversationId String - 会话 ID,通过调用 V2NIMConversationIdUtil 的对应函数创建。
  • 组成方式:用户账号(accountId)|会话类型(V2NIMConversationType)|聊天对象账号(accountId)或群组 ID。
  • 不可设置为空,否则返回 191004 参数错误。
  • iOS
    objective-c- (BOOL)getConversationMuteStatus:(NSString *)conversationId;
    
    参数名称 类型 是否必填 默认值 描述
    conversationId NSString * - 会话 ID,通过调用 V2NIMConversationIdUtil 的对应函数创建。
  • 组成方式:用户账号(accountId)|会话类型(V2NIMConversationType)|聊天对象账号(accountId)或群组 ID。
  • 不可设置为空,否则返回 191004 参数错误。
  • macOS/Windows
    cppvirtual bool getConversationMuteStatus(nstd::string conversationId) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    conversationId nstd::string - 会话 ID,通过调用 V2NIMConversationIdUtil 的对应函数创建。
  • 组成方式:用户账号(accountId)|会话类型(V2NIMConversationType)|聊天对象账号(accountId)或群组 ID。
  • 不可设置为空,否则返回 191004 参数错误。
  • Web/uni-app/小程序
    typescriptgetConversationMuteStatus(conversationId: string): boolean
    
    参数名称 类型 是否必填 默认值 描述
    conversationId string - 会话 ID,通过调用 V2NIMConversationIdUtil 的对应函数创建。
  • 组成方式:用户账号(accountId)|会话类型(V2NIMConversationType)|聊天对象账号(accountId)或群组 ID。
  • 不可设置为空,否则返回 191004 参数错误。
  • 示例代码

    Android
    javaboolean isMute = NIMClient.getService(V2NIMSettingService.class).getConversationMuteStatus(conversationId);
    
    iOS
    objective-c[[NIMSDK sharedSDK] v2SettingService] getConversationMuteStatus:@"conversationId"];
    
    macOS/Windows
    cppauto mute = settingService.getConversationMuteStatus(conversationId);
    
    Web/uni-app/小程序
    typescriptnim.V2NIMSettingService.getConversationMuteStatus('sender|1|receiver')
    

    返回值

    • true:会话消息免打扰开启。
    • false:会话消息免打扰关闭。

    相关回调

    setPushMobileOnDesktopOnline

    接口描述

    设置当桌面端在线时,移动端是否需要推送。

    参数说明

    Android
    javavoid setPushMobileOnDesktopOnline(boolean need, V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
    
    参数名称 类型 是否必填 默认值 描述
    need boolean true 桌面端在线时,移动端是否需要推送:
  • true:需要
  • false:不需要
  • success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    iOS
    objective-c- (void)setPushMobileOnDesktopOnline:(BOOL)need
                                 success:(nullable V2NIMSuccessCallback)success
                                 failure:(nullable V2NIMFailureCallback)failure;
    
    参数名称 类型 是否必填 默认值 描述
    need BOOL true 桌面端在线时,移动端是否需要推送:
  • true:需要
  • false:不需要
  • success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    macOS/Windows
    cppvirtual void setPushMobileOnDesktopOnline(bool need, V2NIMSuccessCallback<void> success, V2NIMFailureCallback failure) = 0;
    
    参数名称 类型 是否必填 默认值 描述
    need bool true 桌面端在线时,移动端是否需要推送:
  • true:需要
  • false:不需要
  • success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    Web/uni-app/小程序
    typescriptsetPushMobileOnDesktopOnline(need: boolean): Promise<void>
    
    参数名称 类型 是否必填 默认值 描述
    need boolean true 桌面端在线时,移动端是否需要推送:
  • true:需要
  • false:不需要
  • 示例代码

    Android
    javaNIMClient.getService(V2NIMSettingService.class).setPushMobileOnDesktopOnline(needPushMobileOnDesktopOnline,
    new V2NIMSuccessCallback<Void>() {
        @Override
        public void onSuccess(Void unused) {
    
        }
    },
    new V2NIMFailureCallback() {
        @Override
        public void onFailure(V2NIMError error) {
    
        }
    });
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] setPushMobileOnDesktopOnline:YES success:^{
        // 成功回调
    } failure:^(V2NIMError * _Nonnull error) {
        // 失败回调
    }];
    
    macOS/Windows
    cppsettingService.setPushMobileOnDesktopOnline(
        true,
        []() {
            // set push mobile on desktop online succeeded
        },
        [](V2NIMError error) {
            // set push mobile on desktop online failed, handle error
        });
    
    Web/uni-app/小程序
    typescriptnim.V2NIMSettingService.setPushMobileOnDesktopOnline(true)
    

    返回值

    无返回值

    相关回调

    Android/iOS/macOS/Windows
    • 请求成功,返回 V2NIMSuccessCallback 回调。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含相关错误码。
    Web/uni-app/小程序

    setDndConfig

    接口描述

    设置推送全局免打扰。

    参数说明

    Android
    javavoid setDndConfig(V2NIMDndConfig config, V2NIMSuccessCallback<Void> success, V2NIMFailureCallback failure);
    
    参数名称 类型 是否必填 默认值 描述
    config V2NIMDndConfig - APNs 推送全局免打扰配置信息
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码
    iOS
    objective-c- (void)setDndConfig:(V2NIMDndConfig *)config;
    
    参数名称 类型 是否必填 默认值 描述
    config V2NIMDndConfig - APNs 推送全局免打扰配置信息
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码

    示例代码

    Android
    javaV2NIMDndConfig dndConfig = V2NIMDndConfig.V2NIMDndConfigBuilder.builder(fromH, fromM, toH, toM).build();
    NIMClient.getService(V2NIMSettingService.class).setDndConfig(dndConfig,
            new V2NIMSuccessCallback<Void>() {
                @Override
                public void onSuccess(Void unused) {
    
                }
            },
            new V2NIMFailureCallback() {
                @Override
                public void onFailure(V2NIMError error) {
                    
                }
            });
    
    iOS
    objective-c[[[NIMSDK sharedSDK] v2SettingService] setDndConfig:config];
    

    返回值

    无返回值

    相关回调

    • 请求成功,返回 V2NIMSuccessCallback 回调。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含相关错误码。

    getDndConfig

    接口描述

    获取推送全局免打扰配置详情。

    参数说明

    Android
    javaV2NIMDndConfig getDndConfig();
    

    无参数

    iOS
    objective-c- (nullable V2NIMDndConfig *)getDndConfig;
    

    无参数

    示例代码

    Android
    javaV2NIMDndConfig dndConfig = NIMClient.getService(V2NIMSettingService.class).getDndConfig();
    
    iOS
    objective-c[NIMSDK.sharedSDK.v2SettingService getDndConfig];
    

    返回值

    V2NIMDndConfig: 推送全局免打扰配置信息

    setOfflinePushConfig(仅 Web)

    接口描述

    设置离线推送配置信息。

    适用于 Web uni-app 编译为移动端的场景。实现步骤请参见 uni-app 离线推送

    参数说明

    typescriptsetOfflinePushConfig(plugin: NIMEStrAnyObj, config: V2NIMOfflinePushConfig): void
    
    参数名称 类型 是否必填 默认值 描述
    plugin NIMEStrAnyObj - 云信提供的离线推送插件,请点击下载
    config V2NIMOfflinePushConfig - 离线推送配置信息

    示例代码

    typescriptconst nimPushPlugin = uni.requireNativePlugin('NIMUniPlugin-PluginModule')
    try {
        this.$store.v2NIM.V2NIMSettingService.setOfflinePushConfig(
            nimPushPlugin,
            {
                miPush: {
                    appId: '111',
                    appKey: '111',
                    certificateName: 'MI_PUSH_CERT'
                },
                vivoPush: {
                    certificateName: 'VIVO_PUSH_CERT'
                },
                oppoPush: {
                    appId: '111',
                    appKey: '111',
                    secret: '111',
                    certificateName: 'OPPO_PUSH_CERT'
                },
                hwPush: {
                    appId: '111',
                    certificateName: 'HUAWEI_PUSH_CERT2'
                },
                fcmPush: {
                    certificateName: 'FCM_PUSH_CERT'
                },
                mzPush: {
                    appId: '111',
                    appKey: '111',
                    certificateName: 'MEIZU_PUSH_CERT'
                },
                honorPush: {
                    certificateName: 'HONOR_PUSH_CERT'
                },
                apns: {
                    certificateName: 'APPLE_PUSH_CERT'
                }
            }
        )
    } catch (err) {
        console.error('setOfflinePushConfig error', err.code, err.detail)
    }
    

    返回值

    void

    相关回调

    setAppBackground(仅 Web)

    接口描述

    设置应用后台状态。

    适用于 Web uni-app 编译为移动端的场景。

    参数说明

    typescriptsetAppBackground(isBackground: boolean, badge?: number): Promise<void>
    
    参数名称 类型 是否必填 默认值 描述
    isBackground boolean - 是否运行在后台
    badge number 0 未读数。仅用于 iOS 端。
    success V2NIMSuccessCallback - 设置成功回调
    failure V2NIMFailureCallback - 设置失败回调,返回错误码

    示例代码

    typescriptnim.V2NIMSettingService.setAppBackground(true)
    

    返回值

    Promise<void>

    相关回调

    • 请求成功,返回 V2NIMSuccessCallback 回调。
    • 请求失败,返回 V2NIMFailuerCallback 回调,包含相关错误码。
    此文档是否对你有帮助?
    有帮助
    去反馈
    • 支持平台
    • API 概览
    • 系统设置监听
    • 系统设置操作
    • 接口类
    • addSettingListener
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • removeSettingListener
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • on("EventName")
    • 支持平台
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • off("EventName")
    • 支持平台
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • setP2PMessageMuteMode
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • getP2PMessageMuteMode
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • getP2PMessageMuteList
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • setTeamMessageMuteMode
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • getTeamMessageMuteMode
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • getConversationMuteStatus
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • setPushMobileOnDesktopOnline
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • setDndConfig
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • getDndConfig
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • setOfflinePushConfig(仅 Web)
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调
    • setAppBackground(仅 Web)
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • 相关回调