diff --git a/README.md b/README.md index e2c27d8..5c2a5fc 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' target 'TargetName' do - pod 'YCDownloadSession', '~> 1.2.4' + pod 'YCDownloadSession', '~> 1.2.5' end ``` @@ -30,6 +30,11 @@ end $ pod install ``` +提示错误 `[!] Unable to find a specification for YCDownloadSession ` 解决办法: + +``` +$ pod setup +``` ## 用法 diff --git a/YCDownloadSession.podspec b/YCDownloadSession.podspec index 038e52e..ad8035b 100644 --- a/YCDownloadSession.podspec +++ b/YCDownloadSession.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "YCDownloadSession" - s.version = "1.2.4" + s.version = "1.2.5" s.summary = "iOS background download video or file" s.description = <<-DESC iOS background download video or file lib diff --git a/YCDownloadSession.xcodeproj/project.pbxproj b/YCDownloadSession.xcodeproj/project.pbxproj index d4d74f4..444c0e2 100644 --- a/YCDownloadSession.xcodeproj/project.pbxproj +++ b/YCDownloadSession.xcodeproj/project.pbxproj @@ -498,7 +498,7 @@ }; D72C84CF1E77D42500EDCEEF = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = 6QXR4W42GG; + DevelopmentTeam = NRL3SRQ267; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.BackgroundModes = { @@ -787,7 +787,7 @@ D72C84E81E77D42500EDCEEF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - DEVELOPMENT_TEAM = 6QXR4W42GG; + DEVELOPMENT_TEAM = NRL3SRQ267; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/YCDownloadSession/ThirdLib/Bugly", @@ -803,7 +803,7 @@ D72C84E91E77D42500EDCEEF /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - DEVELOPMENT_TEAM = 6QXR4W42GG; + DEVELOPMENT_TEAM = NRL3SRQ267; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/YCDownloadSession/ThirdLib/Bugly", diff --git a/YCDownloadSession/Info.plist b/YCDownloadSession/Info.plist index 6610531..9cc7ec3 100644 --- a/YCDownloadSession/Info.plist +++ b/YCDownloadSession/Info.plist @@ -21,7 +21,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.3 + 1.2.5 CFBundleVersion 2 LSRequiresIPhoneOS diff --git a/YCDownloadSession/YCDownloadSession/YCDownloadSession.m b/YCDownloadSession/YCDownloadSession/YCDownloadSession.m index 3ce37a6..b5f473b 100644 --- a/YCDownloadSession/YCDownloadSession/YCDownloadSession.m +++ b/YCDownloadSession/YCDownloadSession/YCDownloadSession.m @@ -44,7 +44,6 @@ + (instancetype)downloadSession { return _instance; } - - (instancetype)init { if (self = [super init]) { NSLog(@"YCDownloadSession init"); @@ -54,15 +53,18 @@ - (instancetype)init { _downloadVersion = @"1.2.3"; [self initDownloadData]; //获取背景session正在运行的(app重启,或者闪退会有任务) - NSMutableDictionary *dictM = [self.session valueForKey:@"tasks"]; - [dictM enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSURLSessionDownloadTask *obj, BOOL * _Nonnull stop) { - YCDownloadTask *task = [self getDownloadTaskWithUrl:[YCDownloadTask getURLFromTask:obj]]; - if(!task){ - [obj cancel]; - }else{ - task.downloadTask = obj; - } - }]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSMutableDictionary *dictM = [self.session valueForKey:@"tasks"]; + [dictM enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSURLSessionDownloadTask *obj, BOOL * _Nonnull stop) { + YCDownloadTask *task = [self getDownloadTaskWithUrl:[YCDownloadTask getURLFromTask:obj]]; + if(!task){ + NSLog(@"[Error] not found task for url: %@", [YCDownloadTask getURLFromTask:obj]); + [obj cancel]; + }else{ + task.downloadTask = obj; + } + }]; + }); [self addNotification]; // if (dictM.count>0) { @@ -330,11 +332,15 @@ - (void)setSaveRootPath:(SetSaveRootPathBlk)srpBlk{ } #pragma mark - private +- (NSURLSessionDownloadTask *)downloadTaskWithUrl:(NSString *)url { + NSURL *downloadURL = [NSURL URLWithString:url]; + NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL]; + return [self.session downloadTaskWithRequest:request]; +} + - (YCDownloadTask *)startNewTaskWithUrl:(NSString *)downloadURLString fileId:(NSString *)fileId delegate:(id)delegate{ - NSURL *downloadURL = [NSURL URLWithString:downloadURLString]; - NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL]; - NSURLSessionDownloadTask *downloadTask = [self.session downloadTaskWithRequest:request]; + NSURLSessionDownloadTask *downloadTask = [self downloadTaskWithUrl:downloadURLString]; YCDownloadTask *task = [self createDownloadTaskItemWithUrl:downloadURLString fileId:fileId delegate:delegate]; task.downloadTask = downloadTask; [downloadTask resume]; @@ -399,10 +405,9 @@ - (void)resumeDownloadTask:(YCDownloadTask *)task { if (!task.downloadTask || task.downloadTask.state == NSURLSessionTaskStateCompleted || task.downloadTask.state == NSURLSessionTaskStateCanceling) { [task.downloadTask cancel]; - NSURL *downloadURL = [NSURL URLWithString:task.downloadURL]; - NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL]; - NSURLSessionDownloadTask *downloadTask = [self.session downloadTaskWithRequest:request]; + NSURLSessionDownloadTask *downloadTask = [self downloadTaskWithUrl:task.downloadURL]; task.downloadTask = downloadTask; + [downloadTask resume]; } [task.downloadTask resume]; [self downloadStatusChanged:YCDownloadStatusDownloading task:task];