Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#Changelog

## 7.0.5 (2014-10-28)

### 修正
* ResumeUpload中httpManager weak引用造成nil
* 重构代码,更符合objc 现代方式


## 7.0.4 (2014-10-17)

### 增加
Expand Down
2 changes: 1 addition & 1 deletion Qiniu.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Common/QNVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

#import <Foundation/Foundation.h>

static const NSString *kQiniuVersion = @"7.0.4";
static const NSString *kQiniuVersion = @"7.0.5";
8 changes: 7 additions & 1 deletion QiniuSDK/Http/QNHttpManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}
Expand Down
12 changes: 2 additions & 10 deletions QiniuSDK/Http/QNUserAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
15 changes: 7 additions & 8 deletions QiniuSDK/Storage/QNResumeUpload.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <QNRecorderDelegate> recorder;
@property int64_t modifyTime;
@property (nonatomic, strong) id <QNRecorderDelegate> recorder;

@property UInt32 chunkCrc;

Expand Down Expand Up @@ -293,18 +293,17 @@ - (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]];
url = [NSString stringWithFormat:@"%@%@", url, keyStr];
}

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];
Expand Down
16 changes: 6 additions & 10 deletions QiniuSDK/Storage/QNUploadOption.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion QiniuSDKTests/QNFileRecorderTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDKTests/QNResumeUploadTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pod "Qiniu", "~> 7.0"
...
```

建议 QNUploadManager 创建一次重复使用,或者使用单例方式创建。

## 测试

``` bash
Expand Down