@@ -434,9 +434,7 @@ - (void)clean {
434434 NSError *error = nil ;
435435 [_fileManager removeItemAtPath: _recorderFilePath error: &error];
436436 if (error) {
437- QNAsyncRunInMain (^{
438- NSLog (@" remove recorder file failed: %@ " , error);
439- });
437+ NSLog (@" remove recorder file failed: %@ " , error);
440438 return ;
441439 }
442440 }
@@ -446,9 +444,7 @@ - (BOOL)checkReportAvailable {
446444
447445 if (!_config.isReportEnable ) return NO ;
448446 if (!(_config.maxRecordFileSize > _config.uploadThreshold )) {
449- QNAsyncRunInMain (^{
450- NSLog (@" maxRecordFileSize must be larger than uploadThreshold" );
451- });
447+ NSLog (@" maxRecordFileSize must be larger than uploadThreshold" );
452448 return NO ;
453449 }
454450 return YES ;
@@ -471,9 +467,7 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
471467 if (![_fileManager fileExistsAtPath: _config.recordDirectory]) {
472468 [_fileManager createDirectoryAtPath: _config.recordDirectory withIntermediateDirectories: YES attributes: nil error: &error];
473469 if (error) {
474- QNAsyncRunInMain (^{
475- NSLog (@" create record directory failed, please check record directory: %@ " , error.localizedDescription );
476- });
470+ NSLog (@" create record directory failed, please check record directory: %@ " , error.localizedDescription );
477471 return ;
478472 }
479473 }
@@ -487,19 +481,21 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
487481 // recordFile存在,拼接文件内容、上传到服务器
488482 QNFile *file = [[QNFile alloc ] init: _recorderFilePath error: &error];
489483 if (error) {
490- QNAsyncRunInMain (^{
491- NSLog (@" create QNFile with path failed: %@ " , error.localizedDescription );
492- });
484+ NSLog (@" create QNFile with path failed: %@ " , error.localizedDescription );
493485 return ;
494486 }
495487
496488 // 判断recorder文件大小是否超过maxRecordFileSize
497489 if (file.size < _config.maxRecordFileSize ) {
498- // 上传信息写入recorder文件
499- NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath: _recorderFilePath];
500- [fileHandler seekToEndOfFile ];
501- [fileHandler writeData: [finalRecordInfo dataUsingEncoding: NSUTF8StringEncoding]];
502- [fileHandler closeFile ];
490+ @try {
491+ // 上传信息写入recorder文件
492+ NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath: _recorderFilePath];
493+ [fileHandler seekToEndOfFile ];
494+ [fileHandler writeData: [finalRecordInfo dataUsingEncoding: NSUTF8StringEncoding]];
495+ [fileHandler closeFile ];
496+ } @catch (NSException *exception) {
497+ NSLog (@" NSFileHandle cannot write data: %@ " , exception.description );
498+ }
503499 }
504500
505501 // 判断是否满足上传条件:文件大于上报临界值 && (首次上传 || 距上次上传时间大于_config.interval)
@@ -530,9 +526,7 @@ - (void)innerReport:(NSString *)jsonString token:(NSString *)token {
530526 }
531527 [self clean ];
532528 } else {
533- QNAsyncRunInMain (^{
534- NSLog (@" upload info report failed: %@ " , error.localizedDescription );
535- });
529+ NSLog (@" upload info report failed: %@ " , error.localizedDescription );
536530 }
537531 [session finishTasksAndInvalidate ];
538532 dispatch_semaphore_signal (self.semaphore );
0 commit comments