diff --git a/CHANGELOG.md b/CHANGELOG.md index 9123edb6..ed480557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ #Changelog +## 7.0.5 (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/Http/QNHttpManager.m b/QiniuSDK/Http/QNHttpManager.m index 475f8672..2ca53d00 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]; } diff --git a/QiniuSDK/Storage/QNResumeUpload.m b/QiniuSDK/Storage/QNResumeUpload.m index 91820695..6ca8621b 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; @@ -32,8 +32,8 @@ @interface QNResumeUpload () @property (nonatomic, strong) NSMutableArray *contexts; @property (nonatomic, readonly, getter = isCancelled) BOOL cancelled; -@property UInt64 modifyTime; -@property (nonatomic, weak) id recorder; +@property int64_t modifyTime; +@property (nonatomic, strong) id recorder; @property UInt32 chunkCrc; @@ -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 9cad61bf..e041a493 100644 --- a/QiniuSDK/Storage/QNUploadOption.m +++ b/QiniuSDK/Storage/QNUploadOption.m @@ -23,17 +23,13 @@ + (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; } 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; } diff --git a/README.md b/README.md index 7c1e55d0..e986d928 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ pod "Qiniu", "~> 7.0" ... ``` +建议 QNUploadManager 创建一次重复使用,或者使用单例方式创建。 + ## 测试 ``` bash