Reputation: 132
Im sorry, i feel kind of dumb, but im having trouble implementing the following code for to download multiple files from the server.I have set up the MultipleDownload.h and MultipleDownload.m files as a new Objective-C class within my app. But not sure how call it from my updateView.m to perfrom the file downloads. As per instructions it says i need to initialize and start downloading with the following lines. I cant figure out where to put that code to start downloading files from urls. Do i have to setup a method within that MultipleDownload.m code and call that method it from another object (updateView.m) to initiate the download? or i do i put those lines into one of the methods in (updateView.m)? I honestly tried both and for some reason i keep getting errors, It says that urls. If i put it in updateView.m it says that self.urls and self.downloads is undeclared identifier. I tried to declare NSMutableArray *urls and MultipleDownload *downloads within my updateView.m and it doesnt seen to work either. Any input would be appreciated.
the MultipleDownload.m and MultipleDownload.h code is located on github: http://github.com/leonho/iphone-libs/tree/master
To initialize and start the download:
self.urls = [NSMutableArray arrayWithObjects:
@"http://maps.google.com/maps/geo?output=json&q=Lai+Chi+Kok,Hong+Kong",
@"http://maps.google.com/maps/geo?output=json&q=Central,Hong+Kong",
@"http://maps.google.com/maps/geo?output=json&q=Wan+Chai,Hong+Kong",
nil];
self.downloads = [[MultipleDownload alloc] initWithUrls: urls];
self.downloads.delegate = self;
Upvotes: 0
Views: 487
Reputation: 21221
What you do is in updateView.h
create @properties for urls (type NSMutableArray) and downloads (type MultiDownload)
then in updateView.m
you add a these functions
//Function to start download
- (void) startDownload
{
self.urls = [NSMutableArray arrayWithObjects:
@"YourURLS",
@"YourURLS",
@"YourURLS",
nil];
self.downloads = [[MultipleDownload alloc] initWithUrls: urls];
self.downloads.delegate = self;
}
//download finished for 1 item
- (void) didFinishDownload:(NSNumber*)idx {
NSLog(@"%d download: %@", [idx intValue], [downloads dataAsStringAtIndex: [idx intValue]]);
}
//download finished for all items
- (void) didFinishAllDownload {
NSLog(@"Finished all download!");
[downloads release];
}
I also suggest that if you have problem understanding self.urls and self.downloads to read some more info about objective c and properties, good luck
Upvotes: 1