Skip to content

Commit 9a1b7a0

Browse files
committed
Merge pull request #80 from longbai/userid
ua use idfv
2 parents 5622a1c + 0befab7 commit 9a1b7a0

File tree

9 files changed

+88
-79
lines changed

9 files changed

+88
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### 增加
66
* 支持 https
77
* 禁止0字节文件上传
8+
* ua加入idfv 便于网络诊断
89

910
### 修正
1011
* QNHttpDelegate.h 头文件名大小写修正

QiniuSDK/Common/QNSystem.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@
1717

1818
BOOL hasNSURLSession(){
1919
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
20-
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
21-
if (sysVersion < 7.0) {
22-
return NO;
23-
}
20+
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
21+
if (sysVersion < 7.0) {
22+
return NO;
23+
}
2424
#else
25-
NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
26-
if ((sysVersion.majorVersion <= 10 && sysVersion.minorVersion < 9)) {
27-
return NO;
28-
}
25+
NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
26+
if ((sysVersion.majorVersion <= 10 && sysVersion.minorVersion < 9)) {
27+
return NO;
28+
}
2929
#endif
30-
return YES;
30+
return YES;
3131
}
3232

3333
BOOL hasAts(){
3434
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
35-
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
36-
if (sysVersion < 9.0) {
37-
return NO;
38-
}
35+
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
36+
if (sysVersion < 9.0) {
37+
return NO;
38+
}
3939
#else
40-
NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
41-
42-
if ((sysVersion.majorVersion <= 10 && sysVersion.minorVersion < 11)) {
43-
return NO;
44-
}
40+
NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
41+
42+
if ((sysVersion.majorVersion <= 10 && sysVersion.minorVersion < 11)) {
43+
return NO;
44+
}
4545
#endif
46-
return YES;
46+
return YES;
4747
}

QiniuSDK/Http/QNHttpManager.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ - (void) sendRequest2:(NSMutableURLRequest *)request
112112

113113
request.URL = url;
114114

115+
[request setTimeoutInterval:_timeout];
116+
117+
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
118+
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
119+
115120
AFHTTPRequestOperation *operation = [_httpManager
116121
HTTPRequestOperationWithRequest:request
117122
success: ^(AFHTTPRequestOperation *operation, id responseObject) {
@@ -151,10 +156,7 @@ - (void) sendRequest2:(NSMutableURLRequest *)request
151156
}
152157
}];
153158
}
154-
[request setTimeoutInterval:_timeout];
155-
156-
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
157-
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
159+
158160
[_httpManager.operationQueue addOperation:operation];
159161
}
160162

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import "QNResponseInfo.h"
1111
#import "QNUserAgent.h"
12+
#import "QNVersion.h"
1213

1314
const int kQNZeroDataSize = -6;
1415
const int kQNInvalidToken = -5;
@@ -96,14 +97,14 @@ + (instancetype)responseInfoWithFileError:(NSError *)error {
9697
return [[QNResponseInfo alloc] initWithStatus:kQNFileError error:error];
9798
}
9899

99-
+ (instancetype)responseInfoOfZeroData:(NSString *)path{
100-
NSString *desc;
101-
if (path == nil) {
102-
desc = @"data size is 0";
103-
}else {
104-
desc = [[NSString alloc] initWithFormat:@"file %@ size is 0", path];
105-
}
106-
return [[QNResponseInfo alloc] initWithStatus:kQNZeroDataSize errorDescription:desc];
100+
+ (instancetype)responseInfoOfZeroData:(NSString *)path {
101+
NSString *desc;
102+
if (path == nil) {
103+
desc = @"data size is 0";
104+
}else {
105+
desc = [[NSString alloc] initWithFormat:@"file %@ size is 0", path];
106+
}
107+
return [[QNResponseInfo alloc] initWithStatus:kQNZeroDataSize errorDescription:desc];
107108
}
108109

109110
- (instancetype)initWithCancelled {
@@ -181,7 +182,7 @@ - (instancetype)init:(int)status
181182
}
182183

183184
- (NSString *)description {
184-
return [NSString stringWithFormat:@"<%@= id: %@, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ ip: %@ duration: %f s time: %llu error: %@>", NSStringFromClass([self class]), _id, _statusCode, _reqId, _xlog, _xvia, _host, _serverIp, _duration, _timeStamp, _error];
185+
return [NSString stringWithFormat:@"<%@= id: %@, ver: %@, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ ip: %@ duration: %f s time: %llu error: %@>", NSStringFromClass([self class]), _id, kQiniuVersion, _statusCode, _reqId, _xlog, _xvia, _host, _serverIp, _duration, _timeStamp, _error];
185186
}
186187

187188
- (BOOL)isCancelled {

QiniuSDK/Http/QNSessionManager.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ - (void) sendRequest2:(NSMutableURLRequest *)request
195195
}
196196
request.URL = url;
197197

198+
[request setTimeoutInterval:_timeout];
199+
200+
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
201+
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
202+
198203
if (progressBlock == nil) {
199204
progressBlock = ^(long long totalBytesWritten, long long totalBytesExpectedToWrite) {
200205
};
@@ -235,10 +240,6 @@ - (void) sendRequest2:(NSMutableURLRequest *)request
235240
delegate.cancelBlock = cancelBlock;
236241
}
237242

238-
[request setTimeoutInterval:_timeout];
239-
240-
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
241-
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
242243
[uploadTask resume];
243244
}
244245

QiniuSDK/Http/QNUserAgent.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
#import "QNVersion.h"
1919

2020
static NSString *clientId(void) {
21+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
22+
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
23+
#else
2124
long long now_timestamp = [[NSDate date] timeIntervalSince1970] * 1000;
2225
int r = arc4random() % 1000;
2326
return [NSString stringWithFormat:@"%lld%u", now_timestamp, r];
27+
#endif
2428
}
2529

2630
static NSString *userAgent(NSString *id) {

QiniuSDK/Storage/QNConfiguration.m

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
const UInt32 kQNBlockSize = 4 * 1024 * 1024;
1414

1515
static void addServiceToDns(QNServiceAddress* address, QNDnsManager *dns) {
16-
NSArray *ips = address.ips;
17-
if (ips == nil) {
18-
return;
19-
}
20-
NSURL *u = [[NSURL alloc] initWithString:address.address];
21-
NSString *host = u.host;
22-
for (int i = 0; i<ips.count; i++) {
23-
[dns putHosts:host ip:ips[i]];
24-
}
16+
NSArray *ips = address.ips;
17+
if (ips == nil) {
18+
return;
19+
}
20+
NSURL *u = [[NSURL alloc] initWithString:address.address];
21+
NSString *host = u.host;
22+
for (int i = 0; i<ips.count; i++) {
23+
[dns putHosts:host ip:ips[i]];
24+
}
2525
}
2626

2727
static void addZoneToDns(QNZone *zone, QNDnsManager* dns){
28-
if (zone.up != nil) {
29-
addServiceToDns(zone.up, dns);
30-
}
31-
if (zone.upBackup != nil) {
32-
addServiceToDns(zone.upBackup, dns);
33-
}
28+
if (zone.up != nil) {
29+
addServiceToDns(zone.up, dns);
30+
}
31+
if (zone.upBackup != nil) {
32+
addServiceToDns(zone.upBackup, dns);
33+
}
3434
}
3535

3636
static QNDnsManager* initDns(QNConfigurationBuilder *builder) {
@@ -55,7 +55,7 @@ + (instancetype)build:(QNConfigurationBuilderBlock)block {
5555
- (instancetype)initWithBuilder:(QNConfigurationBuilder *)builder {
5656
if (self = [super init]) {
5757
_up = builder.zone.up;
58-
_upBackup = builder.zone.upBackup == nil? builder.zone.up:builder.zone.upBackup;
58+
_upBackup = builder.zone.upBackup == nil ? builder.zone.up : builder.zone.upBackup;
5959

6060
_chunkSize = builder.chunkSize;
6161
_putThreshold = builder.putThreshold;
@@ -70,7 +70,7 @@ - (instancetype)initWithBuilder:(QNConfigurationBuilder *)builder {
7070
_converter = builder.converter;
7171

7272
_dns = initDns(builder);
73-
addZoneToDns(builder.zone, _dns);
73+
addZoneToDns(builder.zone, _dns);
7474
}
7575
return self;
7676
}
@@ -101,13 +101,13 @@ - (instancetype)init {
101101

102102
@implementation QNServiceAddress : NSObject
103103

104-
- (instancetype) init:(NSString*)address ips:(NSArray*)ips{
105-
if (self = [super init]) {
106-
_address = address;
107-
_ips = ips;
108-
109-
}
110-
return self;
104+
- (instancetype) init:(NSString*)address ips:(NSArray*)ips {
105+
if (self = [super init]) {
106+
_address = address;
107+
_ips = ips;
108+
109+
}
110+
return self;
111111
}
112112

113113
@end
@@ -124,20 +124,20 @@ - (instancetype)initWithUp:(QNServiceAddress *)up
124124
return self;
125125
}
126126

127-
+ (instancetype)createWithHost:(NSString*)up backupHost:(NSString*)backup ip1:(NSString*)ip1 ip2:(NSString*)ip2{
128-
NSArray* ips = [NSArray arrayWithObjects:ip1,ip2, nil];
129-
NSString* a = [NSString stringWithFormat:@"http://%@", up];
130-
QNServiceAddress *s1 = [[QNServiceAddress alloc] init:a ips:ips];
131-
NSString* b = [NSString stringWithFormat:@"http://%@", backup];
132-
QNServiceAddress *s2 = [[QNServiceAddress alloc] init:b ips:ips];
133-
return [[QNZone alloc] initWithUp:s1 upBackup:s2];
127+
+ (instancetype)createWithHost:(NSString*)up backupHost:(NSString*)backup ip1:(NSString*)ip1 ip2:(NSString*)ip2 {
128+
NSArray* ips = [NSArray arrayWithObjects:ip1,ip2, nil];
129+
NSString* a = [NSString stringWithFormat:@"http://%@", up];
130+
QNServiceAddress *s1 = [[QNServiceAddress alloc] init:a ips:ips];
131+
NSString* b = [NSString stringWithFormat:@"http://%@", backup];
132+
QNServiceAddress *s2 = [[QNServiceAddress alloc] init:b ips:ips];
133+
return [[QNZone alloc] initWithUp:s1 upBackup:s2];
134134
}
135135

136136
+ (instancetype)zone0 {
137137
static QNZone *z0 = nil;
138138
static dispatch_once_t onceToken;
139139
dispatch_once(&onceToken, ^{
140-
z0 = [QNZone createWithHost:@"upload.qiniu.com" backupHost:@"up.qiniu.com" ip1:@"183.136.139.10" ip2:@"115.231.182.136"];
140+
z0 = [QNZone createWithHost:@"upload.qiniu.com" backupHost:@"up.qiniu.com" ip1:@"183.136.139.10" ip2:@"115.231.182.136"];
141141
});
142142
return z0;
143143
}
@@ -146,7 +146,7 @@ + (instancetype)zone1 {
146146
static QNZone *z1 = nil;
147147
static dispatch_once_t onceToken;
148148
dispatch_once(&onceToken, ^{
149-
z1 = [QNZone createWithHost:@"upload-z1.qiniu.com" backupHost:@"up-z1.qiniu.com" ip1:@"106.38.227.28" ip2:@"106.38.227.27"];
149+
z1 = [QNZone createWithHost:@"upload-z1.qiniu.com" backupHost:@"up-z1.qiniu.com" ip1:@"106.38.227.28" ip2:@"106.38.227.27"];
150150
});
151151
return z1;
152152
}

QiniuSDK/Storage/QNFormUpload.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ - (void)put {
103103
};
104104

105105
[_httpManager multipartPost:nextHost
106-
withData:_data
106+
withData:_data
107107
withParams:parameters
108108
withFileName:fileName
109109
withMimeType:_option.mimeType

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ - (instancetype)initWithConfiguration:(QNConfiguration *)config {
6464
_config = config;
6565
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
6666
if (hasNSURLSession()) {
67-
_httpManager = [[QNSessionManager alloc] initWithProxy:config.proxy timeout:config.timeoutInterval urlConverter:config.converter dns:config.dns];
67+
_httpManager = [[QNSessionManager alloc] initWithProxy:config.proxy timeout:config.timeoutInterval urlConverter:config.converter dns:config.dns];
6868
}
6969
else {
70-
_httpManager = [[QNHttpManager alloc] initWithTimeout:config.timeoutInterval urlConverter:config.converter dns:config.dns];
70+
_httpManager = [[QNHttpManager alloc] initWithTimeout:config.timeoutInterval urlConverter:config.converter dns:config.dns];
7171
}
7272
#else
7373
_httpManager = [[QNHttpManager alloc] initWithTimeout:config.timeoutInterval urlConverter:config.converter dns:config.dns];
@@ -128,13 +128,13 @@ - (void) putData:(NSData *)data
128128
});
129129
return;
130130
}
131-
132-
if ([data length] == 0) {
133-
QNAsyncRunInMain( ^{
134-
completionHandler([QNResponseInfo responseInfoOfZeroData:nil], key, nil);
135-
});
136-
return;
137-
}
131+
132+
if ([data length] == 0) {
133+
QNAsyncRunInMain( ^{
134+
completionHandler([QNResponseInfo responseInfoOfZeroData:nil], key, nil);
135+
});
136+
return;
137+
}
138138
QNUpCompletionHandler complete = ^(QNResponseInfo *info, NSString *key, NSDictionary *resp)
139139
{
140140
QNAsyncRunInMain( ^{

0 commit comments

Comments
 (0)