Holger
Holger

Reputation: 356

Send Progress from NSURLSession to ViewController [swift - iOS]

I'm developing an app which handles some downloads in the background. I move the file to the documents directory and save it under the original name (using downloadTask.originalRequest?.URL!.pathExtension). So far so good.

Using

URLSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:) 

I can print out the progress in the console while downloading. But this doesn't help me if I'm using the App on the phone. What I'm expecting to do is to call a function to update a progress bar from here within my View that was initialising the download. But I have no idea how to call it.

Does anybody know how I can find out from which UIViewController (actually most of the time it will be a TableCellViewController) I started the download and how to send the progress to a function of that ViewController?

Upvotes: 1

Views: 1780

Answers (2)

Arco
Arco

Reputation: 944

I 'd like to tell you a good tutorial about this question. NSURLSession Tutorial

Upvotes: 1

Jose Pose S
Jose Pose S

Reputation: 1295

Delegates are often used in the following situations

When a class needs to communicate some information to another class When a class wants to allow another class to customize it The classes don't need to know anything about each other beforehand except that the delegate class conforms to the required protocol.

I the following article you can see how to create a delegate in objective-C and Swift 2.0.

How do I create delegates in Objective-C?

Upvotes: 0

Related Questions