Skip to content

Commit 9b4a558

Browse files
authored
Merge pull request #354 from YangSen-qn/FixNSFileHandleBug
fix NSFileHandle bug
2 parents d66bce1 + 3eedf68 commit 9b4a558

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#Changelog
22

3+
## 7.4.4 (2020-08-13)
4+
## 修正
5+
修复reporter的bug,增加NSHandle的异常捕获。
6+
37
## 7.4.3 (2020-07-27)
48
## 优化
59
优化Dns预取的缓存方案

Qiniu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Qiniu'
3-
s.version = '7.4.3'
3+
s.version = '7.4.4'
44
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/objc-sdk'
66
s.social_media_url = 'http://weibo.com/qiniutek'

QiniuSDK/Storage/QNUploadInfoReporter.m

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

QiniuSDK/Utils/QNVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
/**
1212
* sdk 版本
1313
*/
14-
static NSString *const kQiniuVersion = @"7.4.3";
14+
static NSString *const kQiniuVersion = @"7.4.4";

QiniuSDKTests/QNTestConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
// Copyright (c) 2014年 Qiniu. All rights reserved.
77
//
88

9-
static NSString *const g_token = @"jH983zIUFIP1OVumiBVGeAfiLYJvwrF45S-t22eu:ErzbtICVRZ0h8NM0cE3xq1y6n1M=:eyJzY29wZSI6InpvbmUwLXNwYWNlIiwiZGVhZGxpbmUiOjE1OTY0NDMwODMsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSl9In0=";
9+
static NSString *const g_token = @"jH983zIUFIP1OVumiBVGeAfiLYJvwrF45S-t22eu:DhJHSpDW0NW6luUhQUvGKmBEmT0=:eyJzY29wZSI6InpvbmUwLXNwYWNlIiwiZGVhZGxpbmUiOjE2MDI0OTY2MjUsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKX0ifQ==";

0 commit comments

Comments
 (0)