From 2cf7fc6dc57fdd1e6db7b29ca2eeea886acc571a Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 20:26:15 +0800 Subject: [PATCH 1/8] fixed weak ref abort --- QiniuSDK/Storage/QNResumeUpload.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QiniuSDK/Storage/QNResumeUpload.m b/QiniuSDK/Storage/QNResumeUpload.m index 91820695..466f567a 100644 --- a/QiniuSDK/Storage/QNResumeUpload.m +++ b/QiniuSDK/Storage/QNResumeUpload.m @@ -21,7 +21,7 @@ @interface QNResumeUpload () @property (nonatomic, strong) NSData *data; -@property (nonatomic, weak) QNHttpManager *httpManager; +@property (nonatomic, strong) QNHttpManager *httpManager; @property UInt32 size; @property (nonatomic) int retryTimes; @property (nonatomic, strong) NSString *key; @@ -33,7 +33,7 @@ @interface QNResumeUpload () @property (nonatomic, readonly, getter = isCancelled) BOOL cancelled; @property UInt64 modifyTime; -@property (nonatomic, weak) id recorder; +@property (nonatomic, strong) id recorder; @property UInt32 chunkCrc; From 20445175cdcb0266f60828831fc337dd55d103e3 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 20:26:45 +0800 Subject: [PATCH 2/8] use class init --- QiniuSDK/Http/QNHttpManager.m | 8 +++++++- QiniuSDK/Http/QNUserAgent.m | 12 ++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/QiniuSDK/Http/QNHttpManager.m b/QiniuSDK/Http/QNHttpManager.m index 475f8672..7bcf6327 100644 --- a/QiniuSDK/Http/QNHttpManager.m +++ b/QiniuSDK/Http/QNHttpManager.m @@ -16,8 +16,14 @@ @interface QNHttpManager () @property (nonatomic) AFHTTPRequestOperationManager *httpManager; @end +static NSString *userAgent = nil; + @implementation QNHttpManager ++ (void)initialize{ + userAgent = QNUserAgent(); +} + - (instancetype)init { if (self = [super init]) { _httpManager = [[AFHTTPRequestOperationManager alloc] init]; @@ -69,7 +75,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request }]; } - [request setValue:QNUserAgent() forHTTPHeaderField:@"User-Agent"]; + [request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; [request setValue:nil forHTTPHeaderField:@"Accept-Language"]; [_httpManager.operationQueue addOperation:operation]; } diff --git a/QiniuSDK/Http/QNUserAgent.m b/QiniuSDK/Http/QNUserAgent.m index dee9b7be..527d5d92 100644 --- a/QiniuSDK/Http/QNUserAgent.m +++ b/QiniuSDK/Http/QNUserAgent.m @@ -20,21 +20,13 @@ static NSString *clientId(void) { long long now_timestamp = [[NSDate date] timeIntervalSince1970] * 1000; int r = arc4random() % 1000; - return [NSString stringWithFormat:@"%lld%u", now_timestamp, r]; } -static NSString *_userAgent = nil; - NSString *QNUserAgent(void) { - if (_userAgent) { - return [_userAgent copy]; - } - #if __IPHONE_OS_VERSION_MIN_REQUIRED - _userAgent = [NSString stringWithFormat:@"QiniuObject-C/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], clientId()]; + return [NSString stringWithFormat:@"QiniuObject-C/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], clientId()]; #else - _userAgent = [NSString stringWithFormat:@"QiniuObject-C/%@ (Mac OS X %@; %@)", kQiniuVersion, [[NSProcessInfo processInfo] operatingSystemVersionString], clientId()]; + return [NSString stringWithFormat:@"QiniuObject-C/%@ (Mac OS X %@; %@)", kQiniuVersion, [[NSProcessInfo processInfo] operatingSystemVersionString], clientId()]; #endif - return [_userAgent copy]; } From c3ceedef14514ebb1acbeccab749cbd00368fa3e Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 20:45:19 +0800 Subject: [PATCH 3/8] use iterate block --- QiniuSDK/Http/QNHttpManager.m | 4 ++-- QiniuSDK/Storage/QNUploadOption.m | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/QiniuSDK/Http/QNHttpManager.m b/QiniuSDK/Http/QNHttpManager.m index 7bcf6327..2ca53d00 100644 --- a/QiniuSDK/Http/QNHttpManager.m +++ b/QiniuSDK/Http/QNHttpManager.m @@ -20,8 +20,8 @@ @interface QNHttpManager () @implementation QNHttpManager -+ (void)initialize{ - userAgent = QNUserAgent(); ++ (void)initialize { + userAgent = QNUserAgent(); } - (instancetype)init { diff --git a/QiniuSDK/Storage/QNUploadOption.m b/QiniuSDK/Storage/QNUploadOption.m index 9cad61bf..f6a175a8 100644 --- a/QiniuSDK/Storage/QNUploadOption.m +++ b/QiniuSDK/Storage/QNUploadOption.m @@ -23,17 +23,14 @@ + (NSDictionary *)filteParam:(NSDictionary *)params { return nil; } NSMutableDictionary *ret = [NSMutableDictionary dictionary]; - @autoreleasepool { - NSEnumerator *e = [params keyEnumerator]; - for (NSString *key = [e nextObject]; key != nil; key = [e nextObject]) { - if ([key hasPrefix:@"x:"]) { - id val = params[key]; - if (val != nil) { - ret[key] = params[key]; - } - } + + [params enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSString *obj, BOOL *stop) { + if ([key hasPrefix:@"x:"]) { + ret[key] = obj; } - } + }]; + + return ret; } From 942abdb1d04656938b47b5da82c3994a1817426f Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 20:51:41 +0800 Subject: [PATCH 4/8] iterate block --- QiniuSDK/Storage/QNResumeUpload.m | 9 ++++----- QiniuSDK/Storage/QNUploadOption.m | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/QiniuSDK/Storage/QNResumeUpload.m b/QiniuSDK/Storage/QNResumeUpload.m index 466f567a..690ec7a0 100644 --- a/QiniuSDK/Storage/QNResumeUpload.m +++ b/QiniuSDK/Storage/QNResumeUpload.m @@ -293,7 +293,7 @@ - (void)makeFile:(NSString *)uphost mime = [[NSString alloc] initWithFormat:@"/mimetype/%@", [QNUrlSafeBase64 encodeString:self.option.mimeType]]; } - NSString *url = [[NSString alloc] initWithFormat:@"http://%@/mkfile/%u%@", uphost, (unsigned int)self.size, mime]; + __block NSString *url = [[NSString alloc] initWithFormat:@"http://%@/mkfile/%u%@", uphost, (unsigned int)self.size, mime]; if (self.key != nil) { NSString *keyStr = [[NSString alloc] initWithFormat:@"/key/%@", [QNUrlSafeBase64 encodeString:self.key]]; @@ -301,10 +301,9 @@ - (void)makeFile:(NSString *)uphost } if (self.option && self.option.params) { - NSEnumerator *e = [self.option.params keyEnumerator]; - for (id key = [e nextObject]; key != nil; key = [e nextObject]) { - url = [NSString stringWithFormat:@"%@/%@/%@", url, key, [QNUrlSafeBase64 encodeString:(self.option.params)[key]]]; - } + [self.option.params enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSString *obj, BOOL *stop) { + url = [NSString stringWithFormat:@"%@/%@/%@", url, key, [QNUrlSafeBase64 encodeString:obj]]; + }]; } NSMutableData *postData = [NSMutableData data]; diff --git a/QiniuSDK/Storage/QNUploadOption.m b/QiniuSDK/Storage/QNUploadOption.m index f6a175a8..e041a493 100644 --- a/QiniuSDK/Storage/QNUploadOption.m +++ b/QiniuSDK/Storage/QNUploadOption.m @@ -30,7 +30,6 @@ + (NSDictionary *)filteParam:(NSDictionary *)params { } }]; - return ret; } From c63933b9056ba734179539f0dbb4c11a90a6e1be Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 21:19:10 +0800 Subject: [PATCH 5/8] fixed warning --- CHANGELOG.md | 7 +++++++ Qiniu.podspec | 2 +- QiniuSDK/Common/QNVersion.h | 2 +- QiniuSDK/Storage/QNResumeUpload.m | 2 +- QiniuSDKTests/QNFileRecorderTest.m | 2 +- QiniuSDKTests/QNResumeUploadTest.m | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9123edb6..118dbd22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ #Changelog +## 7.0.4 (2014-10-28) + +### 修正 +* ResumeUpload中httpManager weak引用造成nil +* 重构代码,更符合objc 现代方式 + + ## 7.0.4 (2014-10-17) ### 增加 diff --git a/Qiniu.podspec b/Qiniu.podspec index 6fdef3ca..f0af3b48 100644 --- a/Qiniu.podspec +++ b/Qiniu.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Qiniu' - s.version = '7.0.4' + s.version = '7.0.5' s.summary = 'Qiniu Resource Storage SDK for iOS and Mac' s.homepage = 'https://github.com/qiniu/objc-sdk' s.social_media_url = 'http://weibo.com/qiniutek' diff --git a/QiniuSDK/Common/QNVersion.h b/QiniuSDK/Common/QNVersion.h index c7fdbbf1..0cf1d65b 100644 --- a/QiniuSDK/Common/QNVersion.h +++ b/QiniuSDK/Common/QNVersion.h @@ -8,4 +8,4 @@ #import -static const NSString *kQiniuVersion = @"7.0.4"; +static const NSString *kQiniuVersion = @"7.0.5"; diff --git a/QiniuSDK/Storage/QNResumeUpload.m b/QiniuSDK/Storage/QNResumeUpload.m index 690ec7a0..6ca8621b 100644 --- a/QiniuSDK/Storage/QNResumeUpload.m +++ b/QiniuSDK/Storage/QNResumeUpload.m @@ -32,7 +32,7 @@ @interface QNResumeUpload () @property (nonatomic, strong) NSMutableArray *contexts; @property (nonatomic, readonly, getter = isCancelled) BOOL cancelled; -@property UInt64 modifyTime; +@property int64_t modifyTime; @property (nonatomic, strong) id recorder; @property UInt32 chunkCrc; diff --git a/QiniuSDKTests/QNFileRecorderTest.m b/QiniuSDKTests/QNFileRecorderTest.m index a0408e19..63f4de29 100644 --- a/QiniuSDKTests/QNFileRecorderTest.m +++ b/QiniuSDKTests/QNFileRecorderTest.m @@ -31,7 +31,7 @@ - (void)setUp { _upManager = [[QNUploadManager alloc] initWithRecorder:file ]; #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED - NSString *travis = [[[NSProcessInfo processInfo]environment]objectForKey:@"QINIU_TEST_ENV"]; + NSString *travis = [[NSProcessInfo processInfo]environment][@"QINIU_TEST_ENV"]; if ([travis isEqualToString:@"travis"]) { _inTravis = YES; } diff --git a/QiniuSDKTests/QNResumeUploadTest.m b/QiniuSDKTests/QNResumeUploadTest.m index ee8c8ea3..e86c1a6a 100644 --- a/QiniuSDKTests/QNResumeUploadTest.m +++ b/QiniuSDKTests/QNResumeUploadTest.m @@ -26,7 +26,7 @@ - (void)setUp { [super setUp]; _upManager = [[QNUploadManager alloc] init]; #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED - NSString *travis = [[[NSProcessInfo processInfo]environment]objectForKey:@"QINIU_TEST_ENV"]; + NSString *travis = [[NSProcessInfo processInfo]environment][@"QINIU_TEST_ENV"]; if ([travis isEqualToString:@"travis"]) { _inTravis = YES; } From e50a71e5294c69264d3711cbf339f9998a870056 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 21:24:15 +0800 Subject: [PATCH 6/8] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7c1e55d0..996c03bc 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ pod "Qiniu", "~> 7.0" ... ``` +建议 QNUploadManager 创建一次重复使用,或者使用单例方法创建。 + ## 测试 ``` bash From 08121cc980d5ece4e4bf544d9bf9da1402651458 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 21:28:53 +0800 Subject: [PATCH 7/8] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 996c03bc..e986d928 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ pod "Qiniu", "~> 7.0" ... ``` -建议 QNUploadManager 创建一次重复使用,或者使用单例方法创建。 +建议 QNUploadManager 创建一次重复使用,或者使用单例方式创建。 ## 测试 From 739170a4e81737048f0b1a40a172f8f821414818 Mon Sep 17 00:00:00 2001 From: longbai Date: Tue, 28 Oct 2014 21:40:15 +0800 Subject: [PATCH 8/8] changelog ver --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 118dbd22..ed480557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ #Changelog -## 7.0.4 (2014-10-28) +## 7.0.5 (2014-10-28) ### 修正 * ResumeUpload中httpManager weak引用造成nil