Skip to content

Commit

Permalink
解决 Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"…
Browse files Browse the repository at this point in the history
… bug
  • Loading branch information
onezens committed May 11, 2018
1 parent e1d6f9c commit 4d70f38
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -30,6 +30,11 @@ end
$ pod install
```

提示错误 `[!] Unable to find a specification for YCDownloadSession ` 解决办法:

```
$ pod setup
```

## 用法

Expand Down
2 changes: 1 addition & 1 deletion YCDownloadSession.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions YCDownloadSession.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
};
D72C84CF1E77D42500EDCEEF = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 6QXR4W42GG;
DevelopmentTeam = NRL3SRQ267;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
Expand Down Expand Up @@ -787,7 +787,7 @@
D72C84E81E77D42500EDCEEF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = 6QXR4W42GG;
DEVELOPMENT_TEAM = NRL3SRQ267;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/YCDownloadSession/ThirdLib/Bugly",
Expand All @@ -803,7 +803,7 @@
D72C84E91E77D42500EDCEEF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = 6QXR4W42GG;
DEVELOPMENT_TEAM = NRL3SRQ267;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/YCDownloadSession/ThirdLib/Bugly",
Expand Down
2 changes: 1 addition & 1 deletion YCDownloadSession/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.3</string>
<string>1.2.5</string>
<key>CFBundleVersion</key>
<string>2</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
37 changes: 21 additions & 16 deletions YCDownloadSession/YCDownloadSession/YCDownloadSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ + (instancetype)downloadSession {
return _instance;
}


- (instancetype)init {
if (self = [super init]) {
NSLog(@"YCDownloadSession init");
Expand All @@ -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) {
Expand Down Expand Up @@ -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<YCDownloadTaskDelegate>)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];
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 4d70f38

Please sign in to comment.