-1

I am downloading a file using AFNetworking. But I am not able to keep track of my downloadOperation (i.e. viewController recieving completion callback is dismissed). Is there any api to track the file size changes to compare against the total file size.

I don't want to monitor filesystem changes like these answers:

Can I use KVO to implement this type of behavior.

Community
  • 1
  • 1
Edwin Abraham
  • 645
  • 7
  • 24

1 Answers1

0

Your problem is a design issue. Your download operation is salient to multiple view controllers. The download is started and owned by a view controller that can go out of scope before the download completes.

  1. Change the download operation to a higher level controller object (like your app delegate). That way controllers can initiate downloads or view status of downloads. You may want to define a protocol that interested view controllers implement to allow you to call specific methods on those view controllers.

  2. Dispatch messages about your download operation to interested view controllers from that higher level controller.

Fruity Geek
  • 7,351
  • 1
  • 32
  • 41
  • Yes I am aware of the design. And I am currently maintaining a sharedInstance to handle all my download operations. But sometimes due to network inactivity or unexpected errors the download fails without throwing completion callbacks. In this case I wanted to handle re-download or cancel download options by monitoring changes to file with expiry of one day. – Edwin Abraham Jun 18 '14 at 06:51