diff --git a/CHANGELOG.md b/CHANGELOG.md index 7173a68..0e45895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ ## CHANGE LOG +### v6.2.8 + +- [#74] fop url escape +- [#75] 统一user agent 格式 + +### v6.2.7 + +- [#63] 添加额外错误信息 +- [#64] mkfile 支持 key 为 nil +- [#65] 修正 传入的blockComplete在第一次运行的退出时被释放,如果失败重试会变成nil,导致出错 +- [#70] 修改上传域名为upload.qiniu.com +- [#72] operation.responseObject 返回增加nil 判断 + +### v6.2.6 + +- [#61] 错误信息增加reqid + +### v6.2.5 + +- [#50] update AFN 2.2.3 +- [#52] bugfix: 701 retry + ### v6.2.2 2014-04-09 issue [#44](https://github.com/qiniu/ios-sdk/pull/44) diff --git a/QiniuSDK/QiniuConfig.h b/QiniuSDK/QiniuConfig.h index b0a1040..3be31d4 100644 --- a/QiniuSDK/QiniuConfig.h +++ b/QiniuSDK/QiniuConfig.h @@ -10,4 +10,5 @@ #define kQiniuUpHost @"http://upload.qiniu.com" #define kQiniuUndefinedKey @"?" -#define kQiniuUserAgent @"qiniu-ios-sdk" + +#define kQiniuVersion @"6.2.7" diff --git a/QiniuSDK/QiniuHttpClient.m b/QiniuSDK/QiniuHttpClient.m index d511601..2b68935 100644 --- a/QiniuSDK/QiniuHttpClient.m +++ b/QiniuSDK/QiniuHttpClient.m @@ -9,6 +9,7 @@ #import "QiniuHttpClient.h" #import "QiniuConfig.h" +#import "QiniuUtils.h" @implementation QiniuHttpClient @@ -89,7 +90,7 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)theR failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure{ NSMutableURLRequest *request = (NSMutableURLRequest *)theRequest; - [request addValue:kQiniuUserAgent forHTTPHeaderField:@"User-Agent"]; + [request addValue:qiniuUserAgent() forHTTPHeaderField:@"User-Agent"]; AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request success:success failure:failure]; return operation; @@ -103,7 +104,7 @@ @implementation QiniuPutExtra - (NSDictionary *)convertToPostParams{ NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.params]; if (self.checkCrc == 1) { - params[@"crc32"] = [NSString stringWithFormat:@"%u", (unsigned int)self.crc32]; + params[@"crc32"] = [NSString stringWithFormat:@"%ld", self.crc32]; } return params; } diff --git a/QiniuSDK/QiniuResumableClient.m b/QiniuSDK/QiniuResumableClient.m index fc20c84..7ae600b 100644 --- a/QiniuSDK/QiniuResumableClient.m +++ b/QiniuSDK/QiniuResumableClient.m @@ -8,6 +8,7 @@ #import "QiniuResumableClient.h" #import "QiniuConfig.h" +#import "QiniuUtils.h" @implementation QiniuResumableClient @@ -20,11 +21,11 @@ - (QiniuResumableClient *)initWithToken:(NSString *)token self.token = [[NSString alloc] initWithFormat:@"UpToken %@", token]; self.retryTime = tryTime; self.chunkSize = chunkSize; // 256k - + self.responseSerializer = [AFJSONResponseSerializer serializer]; self.operationQueue = [[NSOperationQueue alloc] init]; [self.operationQueue setMaxConcurrentOperationCount:maxWorkers]; - + return self; } @@ -47,10 +48,10 @@ - (void)mkblock:(NSData *)mappedData NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:callUrl]]; [self setHeaders:request]; - + NSData *postData = [mappedData subdataWithRange:NSMakeRange(offset, bodyLength)]; [request setHTTPBody:postData]; - + QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject) { // TODO: check crc32 @@ -60,7 +61,7 @@ - (void)mkblock:(NSData *)mappedData { complete(operation, error); }; - + AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request success:success failure:failure]; @@ -79,12 +80,12 @@ - (void)chunkPut:(NSData *)mappedData } NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/bput/%@/%d", blockPutRet.host, blockPutRet.ctx, (unsigned int)blockPutRet.offset]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:callUrl]]; - + [self setHeaders:request]; - + NSData *postData = [mappedData subdataWithRange:NSMakeRange(offsetBase + blockPutRet.offset, bodyLength)]; [request setHTTPBody:postData]; - + QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject) { // TODO: check crc32 @@ -94,7 +95,7 @@ - (void)chunkPut:(NSData *)mappedData { complete(operation, error); }; - + AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request success:success failure:failure]; @@ -109,21 +110,21 @@ - (void)blockPut:(NSData *)mappedData complete:(QNCompleteBlock)complete { // @autoreleasepool { - - + + UInt32 offsetBase = blockIndex << QiniuBlockBits; - + __block UInt32 bodyLength = self.chunkSize < blockSize ? self.chunkSize : blockSize; __block QiniuBlkputRet *blockPutRet; __block UInt32 retryTime = self.retryTime; __block BOOL isMkblock = YES; - + QNCompleteBlock __block __weak weakChunkComplete; QNCompleteBlock chunkComplete; weakChunkComplete = chunkComplete = ^(AFHTTPRequestOperation *operation, NSError *error) { if (error != nil) { - + if (retryTime == 0 || isMkblock || [operation.response statusCode] == 701) { complete(operation, error); return; @@ -137,16 +138,16 @@ - (void)blockPut:(NSData *)mappedData retryTime = self.retryTime; isMkblock = NO; blockPutRet = [[QiniuBlkputRet alloc] initWithDictionary:operation.responseObject]; - + UInt32 remainLength = blockSize - blockPutRet.offset; bodyLength = self.chunkSize < remainLength ? self.chunkSize : remainLength; } - + if (blockPutRet.offset == blockSize) { complete(operation, nil); return; } - + [self chunkPut:mappedData blockPutRet:blockPutRet offsetBase:offsetBase @@ -154,7 +155,7 @@ - (void)blockPut:(NSData *)mappedData progress:progressBlock complete:weakChunkComplete]; }; - + [self mkblock:mappedData offsetBase:offsetBase blockSize:blockSize @@ -167,7 +168,7 @@ - (void)blockPut:(NSData *)mappedData + (NSString *)encode:(NSString *)str { str = [[str dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0]; - + // is there other methed? str = [str stringByReplacingOccurrencesOfString:@"+" withString:@"-"]; str = [str stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; @@ -180,31 +181,31 @@ - (void)mkfile:(NSString *)key progress:(QNProgressBlock)progressBlock complete:(QNCompleteBlock)complete { - + NSString *mimeStr = extra.mimeType == nil ? @"" : [[NSString alloc] initWithFormat:@"/mimetype/%@", [QiniuResumableClient encode:extra.mimeType]]; - + NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/mkfile/%u%@", kQiniuUpHost, (unsigned int)fileSize, mimeStr]; - + if (key != nil) { NSString *keyStr = [[NSString alloc] initWithFormat:@"/key/%@", [QiniuResumableClient encode:key]]; callUrl = [NSString stringWithFormat:@"%@%@", callUrl, keyStr]; } - + if (extra.params != nil) { NSEnumerator *e = [extra.params keyEnumerator]; for (id key = [e nextObject]; key != nil; key = [e nextObject]) { callUrl = [NSString stringWithFormat:@"%@/%@/%@", callUrl, key, [QiniuResumableClient encode:[extra.params objectForKey:key]]]; } } - + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:callUrl]]; [self setHeaders:request]; - + NSMutableData *postData = [NSMutableData data]; NSString *bodyStr = [extra.progresses componentsJoinedByString:@","]; [postData appendData:[bodyStr dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:postData]; - + QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject) { complete(operation, nil); @@ -213,7 +214,7 @@ - (void)mkfile:(NSString *)key { complete(operation, error); }; - + AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; @@ -224,7 +225,7 @@ - (void)setHeaders:(NSMutableURLRequest *)request { [request setValue:self.token forHTTPHeaderField:@"Authorization"]; [request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"]; - [request addValue:kQiniuUserAgent forHTTPHeaderField:@"User-Agent"]; + [request addValue:qiniuUserAgent() forHTTPHeaderField:@"User-Agent"]; [request setHTTPMethod:@"POST"]; } @@ -263,14 +264,14 @@ - (BOOL) blockUploadedAndCheck if (blockNumlock == nil) { blockNumlock = [[NSLock alloc] init]; } - + BOOL allBlockOk; - + [blockNumlock lock]; self.uploadedBlockNumber ++; allBlockOk = self.uploadedBlockNumber == self.blockCount; [blockNumlock unlock]; - + return allBlockOk; } @@ -280,13 +281,13 @@ - (float) chunkUploadedAndPercent if (chunkNumlock == nil) { chunkNumlock = [[NSLock alloc] init]; } - + float percent; [chunkNumlock lock]; self.uploadedChunkNumber ++; percent = (float)self.uploadedChunkNumber / self.chunkCount; [chunkNumlock unlock]; - + return percent; } diff --git a/QiniuSDK/QiniuSimpleUploader.m b/QiniuSDK/QiniuSimpleUploader.m index f27f82f..9dbc43c 100644 --- a/QiniuSDK/QiniuSimpleUploader.m +++ b/QiniuSDK/QiniuSimpleUploader.m @@ -10,8 +10,6 @@ #import "QiniuUtils.h" #import "QiniuHttpClient.h" -#define kQiniuUserAgent @"qiniu-ios-sdk" - @interface QiniuSimpleUploader () //@property(nonatomic,copy)NSString *filePath; //@property(nonatomic,assign)uint64_t *fileSize; @@ -58,7 +56,7 @@ - (void) uploadFile:(NSString *)filePath [self.delegate uploadSucceeded:filePath ret:resp]; } }]; - + } @end diff --git a/QiniuSDK/QiniuUtils.h b/QiniuSDK/QiniuUtils.h index f892443..631a1b3 100644 --- a/QiniuSDK/QiniuUtils.h +++ b/QiniuSDK/QiniuUtils.h @@ -11,3 +11,5 @@ NSError *qiniuError(int errorCode, NSString *errorDescription); NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error); + +NSString *qiniuUserAgent(); diff --git a/QiniuSDK/QiniuUtils.m b/QiniuSDK/QiniuUtils.m index b175140..c11b2fe 100644 --- a/QiniuSDK/QiniuUtils.m +++ b/QiniuSDK/QiniuUtils.m @@ -5,6 +5,9 @@ // Created by Qiniu Developers 2013 // +#import + +#import "QiniuConfig.h" #import "QiniuUtils.h" #define kQiniuErrorKey @"error" @@ -15,25 +18,29 @@ } NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error) { - + if (operation == nil || operation.responseObject == nil) { return error; } - + NSMutableDictionary *userInfo = nil; NSInteger errorCode = -1; - + if ([operation.responseObject isKindOfClass:NSDictionary.class]) { userInfo = [NSMutableDictionary dictionaryWithDictionary:operation.responseObject]; } errorCode = [operation.response statusCode]; - + if (!userInfo) { userInfo = [NSMutableDictionary init]; } - + NSString *reqid = [[operation.response allHeaderFields] objectForKey:@"X-Reqid"]; [userInfo setObject:reqid forKey:@"reqid"]; - + return [NSError errorWithDomain:kQiniuErrorDomain code:errorCode userInfo:userInfo]; } + +NSString *qiniuUserAgent() { + return [NSString stringWithFormat:@"Qiniu-iOS/%@ (%@; iOS %@; )", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]]; +}