@@ -433,9 +433,7 @@ - (void)clean {
433433 NSError *error = nil ;
434434 [_fileManager removeItemAtPath: _recorderFilePath error: &error];
435435 if (error) {
436- QNAsyncRunInMain (^{
437- NSLog (@" remove recorder file failed: %@ " , error);
438- });
436+ NSLog (@" remove recorder file failed: %@ " , error);
439437 return ;
440438 }
441439 }
@@ -445,9 +443,7 @@ - (BOOL)checkReportAvailable {
445443
446444 if (!_config.isReportEnable ) return NO ;
447445 if (!(_config.maxRecordFileSize > _config.uploadThreshold )) {
448- QNAsyncRunInMain (^{
449- NSLog (@" maxRecordFileSize must be larger than uploadThreshold" );
450- });
446+ NSLog (@" maxRecordFileSize must be larger than uploadThreshold" );
451447 return NO ;
452448 }
453449 return YES ;
@@ -470,9 +466,7 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
470466 if (![_fileManager fileExistsAtPath: _config.recordDirectory]) {
471467 [_fileManager createDirectoryAtPath: _config.recordDirectory withIntermediateDirectories: YES attributes: nil error: &error];
472468 if (error) {
473- QNAsyncRunInMain (^{
474- NSLog (@" create record directory failed, please check record directory: %@ " , error.localizedDescription );
475- });
469+ NSLog (@" create record directory failed, please check record directory: %@ " , error.localizedDescription );
476470 return ;
477471 }
478472 }
@@ -486,19 +480,21 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
486480 // recordFile存在,拼接文件内容、上传到服务器
487481 QNFile *file = [[QNFile alloc ] init: _recorderFilePath error: &error];
488482 if (error) {
489- QNAsyncRunInMain (^{
490- NSLog (@" create QNFile with path failed: %@ " , error.localizedDescription );
491- });
483+ NSLog (@" create QNFile with path failed: %@ " , error.localizedDescription );
492484 return ;
493485 }
494486
495487 // 判断recorder文件大小是否超过maxRecordFileSize
496488 if (file.size < _config.maxRecordFileSize ) {
497- // 上传信息写入recorder文件
498- NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath: _recorderFilePath];
499- [fileHandler seekToEndOfFile ];
500- [fileHandler writeData: [finalRecordInfo dataUsingEncoding: NSUTF8StringEncoding]];
501- [fileHandler closeFile ];
489+ @try {
490+ // 上传信息写入recorder文件
491+ NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath: _recorderFilePath];
492+ [fileHandler seekToEndOfFile ];
493+ [fileHandler writeData: [finalRecordInfo dataUsingEncoding: NSUTF8StringEncoding]];
494+ [fileHandler closeFile ];
495+ } @catch (NSException *exception) {
496+ NSLog (@" NSFileHandle cannot write data: %@ " , exception.description );
497+ }
502498 }
503499
504500 // 判断是否满足上传条件:文件大于上报临界值 && (首次上传 || 距上次上传时间大于_config.interval)
@@ -524,9 +520,7 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
524520 }
525521 [self clean ];
526522 } else {
527- QNAsyncRunInMain (^{
528- NSLog (@" upload info report failed: %@ " , error.localizedDescription );
529- });
523+ NSLog (@" upload info report failed: %@ " , error.localizedDescription );
530524 }
531525 [session finishTasksAndInvalidate ];
532526 dispatch_semaphore_signal (self.semaphore );
0 commit comments