Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-27-2011, 06:41 AM   #1 (permalink)
New User
 
Join Date: Nov 2011
Posts: 6
Paradox927 is on a distinguished road
Question Shared Download Manager/Queue

I apologize if this is a duplicate post on this forum (issues w the malware warning may have caused a double-post).

Ok, here we go:

I'm trying to figure out how to incorporate a download manager into my app similar to the one found in iDownloader and DownloadLite.

Essentially, I need a way to queue downloads and have the d/l status appear in a tableview showing separate progress indicators. Although it would be nice, I don't need a way to pause/resume these downloads. I do, however, need a way to start these downloads from one viewcontroller and have them continue even if I navigate away from this controller. That's the part I really have no clue how to do.

If any one can point me in the direction of a tutorial or something that would be great. I'm not a copy/paste programmer. I'd much rather learn how to do it.

Oh, I forgot to mention... I'd like to do this with NSOPERATIONQUEUE and NSURLCONNECTION (not ASIHTTPRequest). I don't need/want the extra overhead. Such a Diva! Ha Ha Ha.

Any help is MUCH APPRECIATED!!!

- Paradox927

P.S. I have a similar post on RWForums. If I get any solutions, I will update both threads. Hopefully, this is ok.
Paradox927 is offline   Reply With Quote
Old 11-27-2011, 03:23 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Paradox927 View Post
I apologize if this is a duplicate post on this forum (issues w the malware warning may have caused a double-post).

Ok, here we go:

I'm trying to figure out how to incorporate a download manager into my app similar to the one found in iDownloader and DownloadLite.

Essentially, I need a way to queue downloads and have the d/l status appear in a tableview showing separate progress indicators. Although it would be nice, I don't need a way to pause/resume these downloads. I do, however, need a way to start these downloads from one viewcontroller and have them continue even if I navigate away from this controller. That's the part I really have no clue how to do.

If any one can point me in the direction of a tutorial or something that would be great. I'm not a copy/paste programmer. I'd much rather learn how to do it.

Oh, I forgot to mention... I'd like to do this with NSOPERATIONQUEUE and NSURLCONNECTION (not ASIHTTPRequest). I don't need/want the extra overhead. Such a Diva! Ha Ha Ha.

Any help is MUCH APPRECIATED!!!

- Paradox927

P.S. I have a similar post on RWForums. If I get any solutions, I will update both threads. Hopefully, this is ok.
You don't need to use NSOperation. NSURLConnection is async by it's nature.

What I would suggest doing is creating a download object. Each download object would track a single download. It would set up an NSURLConnection, set itself up as the delegate, and handle the incoming data. Set up a delegate property in those download objects, and set up a protocol to notify the delegate about the status of the upload. You could pass back a percent complete, for example, and a download complete message or download failed message.

You could then write a download queue class that would maintain an array of these download objects. The download queue object would have methods to start a download, including a pointer to delegate. If the delegate pointer isn't nil, the download queue would set the delegate in the download object it creates.

You might want to include some sort of unique ID for each download, either passed in from the caller or generated by the download queue class.

If the unique ID is sent in from the caller, the view controller for your table view could use the row/section number of the entry in the table view as the ID, so it could respond to download status updates by updating a progress indicator on the cell for that row/section, if the cell is still on-screen. (The view controller would call the table view's method cellForRowAtIndexPath to see if the cell for that index path is on-screen.)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-27-2011, 05:38 PM   #3 (permalink)
New User
 
Join Date: Nov 2011
Posts: 6
Paradox927 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
You don't need to use NSOperation. NSURLConnection is async by it's nature.

What I would suggest doing is creating a download object. Each download object would track a single download. It would set up an NSURLConnection, set itself up as the delegate, and handle the incoming data. Set up a delegate property in those download objects, and set up a protocol to notify the delegate about the status of the upload. You could pass back a percent complete, for example, and a download complete message or download failed message.

You could then write a download queue class that would maintain an array of these download objects. The download queue object would have methods to start a download, including a pointer to delegate. If the delegate pointer isn't nil, the download queue would set the delegate in the download object it creates.

You might want to include some sort of unique ID for each download, either passed in from the caller or generated by the download queue class.

If the unique ID is sent in from the caller, the view controller for your table view could use the row/section number of the entry in the table view as the ID, so it could respond to download status updates by updating a progress indicator on the cell for that row/section, if the cell is still on-screen. (The view controller would call the table view's method cellForRowAtIndexPath to see if the cell for that index path is on-screen.)
Thank you for the reply.

I didn't realize this could be done without using NSOperationQueue. Everything I read made some kind of referene to it. This is good news; makes it slightly less complicated now. :-)

Having said that... I'm still confused about the creation of the download queue. The download object is pretty straight forward.

Here's where I'm lost: in my tabbed-application, if I'm in viewController1 (tab 1) and I press a button that fires off the download (which basically creates the downloadObject), and then I navigate to viewController2 (tab 2) to view my current active downloads (aka my uitableview with progress indicators) how do I get access to the downloadQueue's array objects? And when setting the downloadObject's delegate, which controller becomes the delegate?

Clearly, I'm over thinking this. I have a pretty good understanding of protocols and delegates, but this shared "downloadQueue" class is just confusing me. D'oh!
Paradox927 is offline   Reply With Quote
Old 11-27-2011, 06:02 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

To access, the download queue's download objects, you'd create a read only property in the header and redefine it as readwrite in the .m file via a class extension. The reason for making it read only is that other classes should not alter the array. I'll let Duncan answer the delegate question.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-27-2011, 06:24 PM   #5 (permalink)
New User
 
Join Date: Nov 2011
Posts: 6
Paradox927 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
To access, the download queue's download objects, you'd create a read only property in the header and redefine it as readwrite in the .m file via a class extension. The reason for making it read only is that other classes should not alter the array. I'll let Duncan answer the delegate question.
Hi, Domele.

So... would I initialize the downloadQueue in the AppDelegate or set it up as a Singleton?
Paradox927 is offline   Reply With Quote
Old 11-27-2011, 06:45 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Set it up as a singleton.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-27-2011, 07:31 PM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Paradox927 View Post
Thank you for the reply.

I didn't realize this could be done without using NSOperationQueue. Everything I read made some kind of referene to it. This is good news; makes it slightly less complicated now. :-)

Having said that... I'm still confused about the creation of the download queue. The download object is pretty straight forward.

Here's where I'm lost: in my tabbed-application, if I'm in viewController1 (tab 1) and I press a button that fires off the download (which basically creates the downloadObject), and then I navigate to viewController2 (tab 2) to view my current active downloads (aka my uitableview with progress indicators) how do I get access to the downloadQueue's array objects? And when setting the downloadObject's delegate, which controller becomes the delegate?

Clearly, I'm over thinking this. I have a pretty good understanding of protocols and delegates, but this shared "downloadQueue" class is just confusing me. D'oh!

I didn't read your original post closely enough it seems.

If you have 2 view controllers that need to monitor your download queue, you might want to use notifications instead of delegate messages.

We wrote a download manager that does either. When you queue a download, you can provide a delegate and/or a notification message to send. If you provide a notification message, it broadcasts notifications.

In your case, you will want to provide different types of notifications. (download progress and download completed/failed messages). You could use the userInfo in the notification to provide a message type and extra data (just create a dictionary format that lets you pass different kinds of info back. have a messageType key. For message type downloadProgress, have another key progressValue which contains and NSNumber value from 0 to 1 for the percent complete. Have another messageType downloadComplete with no additional keys in the dictionary, and another message type downloadFailed, with an error message key/value pair.)

In our case, we used the URL to the file we were downloading as the notification name. In your case, you could use the index of the item in your data source, in string format. Then, when a delegate message comes in, you can use the index to find the item and update the download status, display the image, or whatever.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-28-2011, 04:21 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default

this can be done with such a minimal amount of code you wouldnt believe it! just look into asihttprequest. its amazing!! i use it all the time for my new apps that include downloading.
sumosumo84 is offline   Reply With Quote
Old 11-28-2011, 04:47 PM   #9 (permalink)
New User
 
Join Date: Nov 2011
Posts: 6
Paradox927 is on a distinguished road
Default

I'm just about done implementing a fully functional solution (based on all the wonderful feedback). Since I'm already using CoreData in this app, it made a few things a little easier.

I'll post back more details once I work out all the "funny-little" details (quirks).

THANKS AGAIN!!

- Paradox927
Paradox927 is offline   Reply With Quote
Old 11-28-2011, 04:49 PM   #10 (permalink)
New User
 
Join Date: Nov 2011
Posts: 6
Paradox927 is on a distinguished road
Default

Quote:
Originally Posted by sumosumo84 View Post
this can be done with such a minimal amount of code you wouldnt believe it! just look into asihttprequest. its amazing!! i use it all the time for my new apps that include downloading.
I had considered using that, but I'm such a control freak! Ha Ha! Besides... I didn't want to bring in all the extra overhead if I didn't need it.

BTW... I heard a rumor that it may be discontinued??? Is that true??? Nah... can't be. It seems so popular.
Paradox927 is offline   Reply With Quote
Reply

Bookmarks

Tags
download queue, nsoperationqueue, uiprogressbar, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 411
16 members and 395 guests
AppsBlogger, chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0