Miscellaneous Features
Update time: 2023/02/09 07:48:31
Catch exceptions handling database
Register the exception handler
- Database exception object
objc/**
* Database exception info
*/
@interface NIMDatabaseException : NSObject
/**
* Database exception
*/
@property (nonatomic,assign,readonly) NIMDatabaseExceptionType exception;
/**
* Database exception info
*/
@property (nullable,nonatomic,copy,readonly) NSString * message;
/**
* Database file path in a sandbox
*/
@property (nullable,nonatomic,copy,readonly) NSString * databasePath;
/**
* Register a database exception handler
* @param handler custom handler
*/
+ (void)registerExceptionHandler:(id<NIMDatabaseHandleExceptionProtocol>)handler;
@end
Sample code:
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 = @"database corruption";
break;
default:
break;
}
NSString * msg = [NSString stringWithFormat:@"Total count %zu\nError: %@\nMessage:%@\npath:%@\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
Transparent data transmission
Transfer the data of HTTP requests to the app server
objective-c@protocol NIMPassThroughManager <NSObject>
/**
* Transparently transmit HTTP requests to application services
*
* @param reqData HTTP data in pass-through mode
* @param completion Callback for operation completion
* @discussion If the operation is successful, CommsEase server will send a group notification message for banning
*/
- (void)passThroughHttpReq:(NIMPassThroughHttpData *)reqData
completion:(nullable NIMPassThroughCompletedBlock)completion;
Properties
Parameter | Type | Description |
---|---|---|
reqData | NIMPassThroughHttpData | Transferred data of an HTTP request |
completion | NIMPassThroughCompletedBlock | Callback for completion |
Callback for data transfer
objective-c/**
* Transparent transmission service management callback
*/
@protocol NIMPassThroughManagerDelegate <NSObject>
@optional
/**
* Received messages delivered in pass-through mode
*
* @param recvData Received messages data
*/
- (void)didReceivedPassThroughMsg:(NIMPassThroughMsgData* __nullable)recvData;
@end
Manage callbacks
objc[NIMSDK.sharedSDK.passThroughManager addDelegate:yourDelegate]; // Register a callback
[NIMSDK.sharedSDK.passThroughManager removeDelegate:yourDelegate]; // Unregister a callback.
Was this page helpful?