Skip to content

Commit 36b09a1

Browse files
author
eagleychen
committed
添加数据判空保护
1 parent 5d3cbe5 commit 36b09a1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,23 @@ - (void)appGetUserConfig:(TIoTP2PAPPConfig *)appconfig {
420420
reqlog.HTTPMethod = @"POST";
421421
reqlog.HTTPBody = [NSJSONSerialization dataWithJSONObject:accessParam options:NSJSONWritingFragmentsAllowed error:nil];;
422422
NSURLSessionDataTask *tasklog = [[NSURLSession sharedSession] dataTaskWithRequest:reqlog completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
423-
423+
424424
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
425-
if (httpResponse.statusCode == 200) {
425+
if (httpResponse.statusCode == 200 && data != nil) {
426426
NSError *jsonerror = nil;
427427
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonerror];
428428
// NSLog(@"log serverapi:content===>%@, param==>%@, data===>%@",content,accessParam,dic);
429-
[self setAppLogConfig:[[dic objectForKey:@"data"] objectForKey:@"Data"]];
429+
430+
// 检查服务器返回的业务错误码
431+
NSNumber *code = [dic objectForKey:@"code"];
432+
if (code && [code integerValue] == 0) {
433+
// 业务成功,处理配置数据
434+
[self setAppLogConfig:[[dic objectForKey:@"data"] objectForKey:@"Data"]];
435+
} else {
436+
// 业务失败,记录错误日志
437+
NSString *errorMsg = [dic objectForKey:@"msg"] ?: @"Unknown error";
438+
NSLog(@"AppGetUserConfig failed: %@", errorMsg);
439+
}
430440
}
431441
}];
432442
[tasklog resume];

0 commit comments

Comments
 (0)