只需 2 步,定位集成融云时的解体与谬误 - iOS 篇

在集成融云 iOS SDK 时候,多多少少都会遇到一些问题,可能是解体,也可能是性能接口谬误回调,对于刚接触 SDK 的开发者,不免大刀阔斧,上面分享一个疾速定位问题的办法,只需 2 步哟~

办法的中心思想就是“疾速拿到 log,通过剖析 log 定位问题“
步骤 1:

增加上面代码,将 log 写入沙盒

- (BOOL)application:(UIApplication *)application    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {          //重定向 log 到本地问题          //在 info.plist 中关上 Application supports iTunes file sharing      if (![[[UIDevice currentDevice] model] isEqualToString:@"iPhone Simulator"]) {          [self redirectNSlogToDocumentFolder];      }    //设置Log级别,开发阶段打印具体log    [RCIMClient sharedRCIMClient].logLevel = RC_Log_Level_Info;}- (void)redirectNSlogToDocumentFolder {  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  NSString *documentDirectory = [paths objectAtIndex:0];  NSDate *currentDate = [NSDate date];  NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];  [dateformatter setDateFormat:@"MMddHHmmss"];  NSString *formattedDate = [dateformatter stringFromDate:currentDate];  NSString *fileName = [NSString stringWithFormat:@"rc%@.log", formattedDate];  NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];  freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);  freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);}
步骤 2:

退出第 1 步代码后运行我的项目,复现问题后,从”沙盒/Documents“门路下导出 rc 结尾的 log 文件,应用文本编辑工具关上该文件。

  • 如果是解体,在 log 中能找到对应的解体信息,例如:

      * 找不到办法 unrecognized selector sent to instance   * 数组越界 [__NSArrayM objectAtIndex:]: index4beyond bounds [0..1] 等等。
  • 如果是 SDK 性能接口谬误,能够在 log 中搜寻到错误码,融云的错误码根本都是五位数字,以 ”3“结尾,例如:

      * 31004:“Token 有效”,是应用的 token 和 appkey 不匹配。  * 33001:“SDK 没有初始化”,是须要先初始化 SDK 能力调用其余接口。  * 33003:“开发者接口调用时传入的参数谬误”,是调用接口时候传入的参数有误,有空对象的可能性比拟大。

    更多错误码链接:https://docs.rongcloud.cn/v4/...

总结,通过下面简略的 2 个步骤,就能够定位大部分问题,只是错误码解释如果不够明确的话,就还得提工单问,然而也能节俭一部分交换老本,毕竟如果创立工单就把 log 贴身,失去针对性回复去解决问题的效率也会高很多。心愿明天的分享能够帮忙到大家。