其他
更新时间: 2024/03/14 17:08:34
数据库异常捕获
注册异常处理Handler
- 数据库异常对象
objc/**
* 数据库异常信息
*/
@interface NIMDatabaseException : NSObject
/**
* 异常
*/
@property (nonatomic,assign,readonly) NIMDatabaseExceptionType exception;
/**
* 数据库异常信息
*/
@property (nullable,nonatomic,copy,readonly) NSString * message;
/**
* 数据库文件沙盒路径
*/
@property (nullable,nonatomic,copy,readonly) NSString * databasePath;
/**
* 注册数据库异常处理对象
* @param handler 用户自定义处理对象
*/
+ (void)registerExceptionHandler:(id<NIMDatabaseHandleExceptionProtocol>)handler;
@end
实例代码:
objcNTESDbExceptionHandler * handler = [[NTESDbExceptionHandler alloc] init];
[NIMDatabaseException registerExceptionHandler:handler];
- Demo展示
objc// NTESDbExceptionHandler.m
@implementation NTESDbExceptionHandler
- (void)handleException:(NIMDatabaseException *)exception
{
self.count ++;
NSString * codeType = nil;
switch (exception.exception) {
case NIMDatabaseExceptionTypeBadDb:
codeType = @"数据库损坏";
break;
default:
break;
}
NSString * msg = [NSString stringWithFormat:@"总次数%zu\n错误:%@\n信息:%@\n路径:%@\n",self.count, codeType,exception.message, exception.databasePath];
NSLog(@"handleException: %@",msg);
[[UIApplication sharedApplication].keyWindow hideToasts];
[[UIApplication sharedApplication].keyWindow makeToast:msg
duration:3
position:CSToastPositionCenter];
}
@end
透传
透传Http请求到应用服务
objective-c@protocol NIMPassThroughManager <NSObject>
/**
* 透传HTTP请求到应用服务
*
* @param reqData 透传的Http数据
* @param completion 经验操作完成后的回调
* @discussion 操作成功后,云信服务器会下发禁言的群通知消息
*/
- (void)passThroughHttpReq:(NIMPassThroughHttpData *)reqData
completion:(nullable NIMPassThroughCompletedBlock)completion;
属性列表
参数 | 类型 | 说明 |
---|---|---|
reqData | NIMPassThroughHttpData | 透传的Http数据 |
completion | NIMPassThroughCompletedBlock | 经验操作完成后的回调 |
透传回调
objective-c/**
* 透传服务管理回调
*/
@protocol NIMPassThroughManagerDelegate <NSObject>
@optional
/**
* 收到透传消息
*
* @param recvData 收到的透传消息数据
*/
- (void)didReceivedPassThroughMsg:(NIMPassThroughMsgData* __nullable)recvData;
@end
回调管理
objective-c[NIMSDK.sharedSDK.passThroughManager addDelegate:yourDelegate]; // 注册回调
[NIMSDK.sharedSDK.passThroughManager removeDelegate:yourDelegate]; // 注销回调
此文档是否对你有帮助?