From fe3e29e1f0a80c7795bafb877dbcc84752d153eb Mon Sep 17 00:00:00 2001 From: longbai Date: Sat, 9 Aug 2014 11:14:29 +0800 Subject: [PATCH] add client id --- QiniuSDK/QiniuUtils.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/QiniuSDK/QiniuUtils.m b/QiniuSDK/QiniuUtils.m index d7a9603..f35216d 100644 --- a/QiniuSDK/QiniuUtils.m +++ b/QiniuSDK/QiniuUtils.m @@ -41,12 +41,23 @@ return [NSError errorWithDomain:kQiniuErrorDomain code:errorCode userInfo:userInfo]; } +static NSString* clientId(){ + long long now_timestamp = [[NSDate date] timeIntervalSince1970]*1000; + int r = arc4random()%1000; + return [NSString stringWithFormat:@"%lld%u", now_timestamp, r]; +} + +static NSString* _clientId = nil; + NSString *qiniuUserAgent() { - return [NSString stringWithFormat:@"Qiniu-iOS/%@ (%@; iOS %@; )", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]]; + if (_clientId == nil){ + _clientId = clientId(); + } + return [NSString stringWithFormat:@"Qiniu-iOS/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], _clientId]; } BOOL isRetryHost(AFHTTPRequestOperation *operation) { - + NSInteger errorCode = [operation.response statusCode]; if (errorCode / 100 == 4 || errorCode / 100 == 6 || errorCode / 100 == 7) {