Just 2 steps to locate crashes and errors when integrating cloud integration-iOS articles

Just 2 steps to locate crashes and errors when integrating cloud integration-iOS articles

When integrating Rongyun iOS SDK, you will encounter some problems more or less. It may be a crash or a function interface error callback. For developers who are new to the SDK, they will inevitably be helpless. Here is a way to quickly locate the problem. It takes 2 steps~

#####The central idea of ​​the method is to "get the log quickly, and locate the problem by analyzing the log"

#####step 1:

​ Add the following code to write log into the sandbox

- (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);

}

#####Step 2:

​ Run the project after adding the code in step 1. After reproducing the problem, export the log file starting with rc from the "Sandbox/Documents" path, and open the file with a text editing tool.

  • If it is a crash, the corresponding crash information can be found in the log, for example:

    • Can't find method unrecognized selector sent to instance
    • Array out of bounds [__NSArrayM objectAtIndex:]: index4beyond bounds [0..1] and so on.
  • If it is an SDK function interface error, you can search for the error code in the log. Rongyun's error codes are basically five digits, starting with "3", for example:

    • 31004: "Token is invalid", the token used does not match the appkey.
    • 33001: "SDK is not initialized", it is necessary to initialize the SDK before calling other interfaces.
    • 33003: "The parameter passed in when calling the developer interface is wrong" means that the parameter passed in when calling the interface is wrong, and there is a greater possibility of empty objects.

    More error code links: https://docs.rongcloud.cn/v4/views/im/ui/code/ios.html

In summary, through the above two simple steps, most problems can be located, but if the error code explanation is not clear enough, you have to ask a ticket, but it can also save part of the communication cost. After all, if you create a ticket, log The efficiency of getting targeted responses to solve problems will be much higher if you are close to your body. I hope today’s sharing can help everyone.

Guess you like

Origin blog.51cto.com/15056506/2678297