Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading not starting #30

Open
yatendray opened this issue Jul 1, 2016 · 3 comments
Open

Downloading not starting #30

yatendray opened this issue Jul 1, 2016 · 3 comments

Comments

@yatendray
Copy link

I download latest code from Github and try to run the code.When I click on start download button nothing happend.

Another thing I want to know that how to use it for custom table cells

Thanks

@MSavisko
Copy link

MSavisko commented Jul 12, 2016

  1. Find in demo project TWRDownloadManager.m

  2. Find EMPTY method with name:
    - (void)downloadFileForURL:(NSString *)urlString withName:(NSString *)fileName inDirectoryNamed:(NSString *)directory progressBlock:(void(^)(CGFloat progress))progressBlock remainingTime:(void(^)(NSUInteger seconds))remainingTimeBlock completionBlock:(void(^)(BOOL completed))completionBlock enableBackgroundMode:(BOOL)backgroundMode

  3. Add thier code:
    NSURL *url = [NSURL URLWithString:urlString];
    if (!fileName) {
    fileName = [urlString lastPathComponent];
    }

    if (![self fileDownloadCompletedForUrl:urlString]) {
    NSLog(@"File is downloading!");
    } else if (![self fileExistsWithName:fileName inDirectory:directory]) {
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSessionDownloadTask *downloadTask;
    if (backgroundMode) {
    downloadTask = [self.backgroundSession downloadTaskWithRequest:request];
    } else {
    downloadTask = [self.session downloadTaskWithRequest:request];
    }
    TWRDownloadObject *downloadObject = [[TWRDownloadObject alloc] initWithDownloadTask:downloadTask progressBlock:progressBlock remainingTime:remainingTimeBlock completionBlock:completionBlock];
    downloadObject.startDate = [NSDate date];
    downloadObject.fileName = fileName;
    downloadObject.directoryName = directory;
    [self.downloads addEntriesFromDictionary:@{urlString:downloadObject}];
    [downloadTask resume];
    } else {
    NSLog(@"File already exists!");
    }

  4. Don't forget to change App Transport Security policy requires the use of a secure connection.

  5. Ready for work, you can find in my fork, there: https://github.com/MSavisko/TWRDownloadManager.git

@RajChanchal
Copy link

@MSavisko Do you have any idea why did the developer keep the method definition empty? I am wondering!

@MSavisko
Copy link

@RajChanchal human mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants