From 647fcc6a433b3f455173a86ed271385334134c81 Mon Sep 17 00:00:00 2001 From: Melvin Date: Mon, 24 Oct 2016 15:45:11 +0800 Subject: [PATCH 1/3] 012 --- .swift-version | 1 + TFUploadAssistant.podspec | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..bb576db --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +2.3 diff --git a/TFUploadAssistant.podspec b/TFUploadAssistant.podspec index 07cd24b..f349d31 100644 --- a/TFUploadAssistant.podspec +++ b/TFUploadAssistant.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TFUploadAssistant' - s.version = '0.1.0' + s.version = '0.1.2' s.summary = '时光流影文件上传辅助工具' # This description is used to generate tags and improve search results. @@ -24,7 +24,7 @@ TODO: Add long description of the pod here. s.homepage = 'https://github.com/TimeFaceCoder/TFUploadAssistant' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Melvin' => 'yangmin@timeface.cn' } - s.source = { :git => 'https://github.com/TimeFaceCoder/TFUploadAssistant.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/TimeFaceCoder/TFUploadAssistant.git', :branch => 'lib_demo' } s.social_media_url = 'https://twitter.com/melvin0204' s.ios.deployment_target = '8.0' @@ -32,13 +32,15 @@ TODO: Add long description of the pod here. s.platform = :ios, '8.0' s.source_files = 'TFUploadAssistant/Classes/**/*' - + # s.resource_bundles = { # 'TFUploadAssistant' => ['TFUploadAssistant/Assets/*.png'] # } s.public_header_files = [ 'TFUploadAssistant/Classes/TFUploadAssistant.h', + 'TFUploadAssistant/Classes/TFUploadCommon/TFFileProtocol.h', + 'TFUploadAssistant/Classes/TFUploadCommon/TFPHAssetFile.h', 'TFUploadAssistant/Classes/TFConfiguration.h', 'TFUploadAssistant/Classes/TFUploadOperationProtocol.h' ] From 68835fddf51c36455e6b601066c3fb2e094eadb5 Mon Sep 17 00:00:00 2001 From: baozhenhua Date: Sat, 5 Nov 2016 09:22:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.xcworkspace/contents.xcworkspacedata | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 TFUploadAssistant.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/TFUploadAssistant.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/TFUploadAssistant.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..94b2795 --- /dev/null +++ b/TFUploadAssistant.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + From 1ca9c0630487f5f846c0d6f5e7ecbbf536740db1 Mon Sep 17 00:00:00 2001 From: baozhenhua Date: Thu, 10 Nov 2016 18:42:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?lib=5Fdemo=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TFUploadAssistant/Classes/TFUploadAssistant.m | 94 +++++++++++++------ 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/TFUploadAssistant/Classes/TFUploadAssistant.m b/TFUploadAssistant/Classes/TFUploadAssistant.m index a6a8279..89e1850 100644 --- a/TFUploadAssistant/Classes/TFUploadAssistant.m +++ b/TFUploadAssistant/Classes/TFUploadAssistant.m @@ -42,7 +42,7 @@ - (instancetype)initWithConfiguration:(TFConfiguration *)config { _pool = [[YYDispatchQueuePool alloc] initWithName:@"cn.timeface.upload.read" queueCount:10 qos:NSQualityOfServiceBackground]; - + _configuration = config; _uploadHandlers = [NSMutableDictionary dictionary]; _progressHandlers = [NSMutableDictionary dictionary]; @@ -59,12 +59,12 @@ - (instancetype)initWithConfiguration:(TFConfiguration *)config { + (instancetype)sharedInstanceWithConfiguration:(TFConfiguration *)config { static TFUploadAssistant *sharedInstance = nil; - + static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] initWithConfiguration:config]; }); - + return sharedInstance; } @@ -105,9 +105,9 @@ - (void) putData:(NSData *)data if ([TFUploadAssistant checkAndNotifyError:key token:token input:data complete:completionHandler]) { return; } - + id uploadOperation = nil; - + if(_configuration.uploadType == TFUploadTypeAliyun) { uploadOperation = [TFAliUploadOperation uploadOperationWithData:data @@ -126,7 +126,7 @@ - (void) putData:(NSData *)data // complete:completionHandler // config:_configuration]; } - + dispatch_async([_pool queue], ^{ [uploadOperation start]; }); @@ -223,20 +223,33 @@ - (void) putFileInternal:(id)file } if (!progressHandler) { progressHandler = ^(NSString *key,NSString *token ,float percent) { - [self calculateTotalProgress:token key:key progress:percent]; + @synchronized(weakSelf) + { + TFAsyncRunInMain(^{ + [self calculateTotalProgress:token key:key progress:percent]; + }); + } }; } TFUpCompletionHandler uploadComplete = ^(TFResponseInfo *info, NSString *key, NSString *token, BOOL success){ //remove from operations __typeof(&*weakSelf) strongSelf = weakSelf; - [strongSelf removeOperationsByToken:token identifier:key]; - if (completionHandler) { - completionHandler(info,key,token,success); - } - if (!success) { - //上传失败,加入错误列表 - TFULogDebug(@"update object :%@ error add failed operations",key); - [strongSelf cacheFailedOperationsByToken:token objectKey:key filePath:[file path]]; + @synchronized(strongSelf) + { + [strongSelf removeOperationsByToken:token identifier:key]; + if (completionHandler) { + completionHandler(info,key,token,success); + } + + if (!success) { + //上传失败,加入错误列表 + // TFULogDebug(@"update object :%@ error add failed operations",key); + [strongSelf cacheFailedOperationsByToken:token objectKey:key filePath:[file path]]; + } + else + { + [strongSelf removeFailedOperationsByToken:token objectKey:key]; + } } //TFULogDebug(@"update object :%@ consume %f seconds",key,info.duration); }; @@ -293,9 +306,9 @@ - (void)initOperations:(NSArray *)keys token:(NSString *)token { [progressDic setObject:[NSNumber numberWithFloat:0] forKey:objectKey]; [self cacheOperationsByToken:token identifier:objectKey]; } - + NSLog(@"%@", @(_uploadOperations.allKeys.count)); - + //cache task list [[TFFileRecorder sharedInstance] set:kTFUploadOperationsKey object:_uploadOperations]; } @@ -372,14 +385,29 @@ - (void)cacheFailedOperationsByToken:(NSString *)token objectKey:(NSString *)obj - (void)removeFailedOperationsByToken:(NSString *)token objectKey:(NSString *)objectKey { NSMutableDictionary *entry = [_failedOperations objectForKey:token]; - if (entry) { + if(!entry) + { + return; + } + NSArray* allkeys = [entry allKeys]; + BOOL isExist = NO; + for(NSString* key in allkeys) + { + if([key isEqualToString:objectKey]) + { + isExist = YES; + break; + } + } + if (isExist && entry) { [entry removeObjectForKey:objectKey]; + //{objectkey:filepath} + [_failedOperations setObject:entry forKey:token]; + //save to disk + [[TFFileRecorder sharedInstance] set:kTFUploadFailedOperationsKey object:_failedOperations]; } - //{objectkey:filepath} - [_failedOperations setObject:entry forKey:token]; - //save to disk - [[TFFileRecorder sharedInstance] set:kTFUploadFailedOperationsKey object:_failedOperations]; } + #pragma mark - 检测未完成任务列表 - (void)checkTask { @@ -387,7 +415,7 @@ - (void)checkTask { TFAsyncRun(^{ __typeof(&*weakSelf) strongSelf = weakSelf; @autoreleasepool { - + //存在正在上传的图片 // NSMutableDictionary *uploadOperations = [[TFFileRecorder sharedInstance] get:kTFUploadOperationsKey]; // if(uploadOperations) @@ -397,14 +425,14 @@ - (void)checkTask { // //{objectkey:filepath} // if (entry) { // for (NSString *objectKey in entry) { -// +// // NSLog(@"%@", objectKey); -// +// // } // } // } // } - + //不一定有上传失败的图片 NSMutableDictionary *failedOperations = [[TFFileRecorder sharedInstance] get:kTFUploadFailedOperationsKey]; if (failedOperations) { @@ -421,9 +449,12 @@ - (void)checkTask { token:token progress:NULL completion:^(TFResponseInfo *info, NSString *key, NSString *token, BOOL success) { - if (success) { - [strongSelf removeFailedOperationsByToken:token objectKey:objectKey]; - } + if (success) { + @synchronized(strongSelf) + { + [strongSelf removeFailedOperationsByToken:token objectKey:objectKey]; + } + } }]; } else { @@ -437,7 +468,10 @@ - (void)checkTask { progress:NULL completion:^(TFResponseInfo *info, NSString *key, NSString *token, BOOL success) { if (success) { - [strongSelf removeFailedOperationsByToken:token objectKey:objectKey]; + @synchronized(strongSelf) + { + [strongSelf removeFailedOperationsByToken:token objectKey:objectKey]; + } } }]; }