IOS downloads each file separately or in one archive

I am working on an iOS application where I need to regularly “push” new levels on the device. The level is an HTML5 page with images, javascript and css files. I need all level files to be cached locally before the level can be played by the user. Each level is about 1.5 MB. I am going to archive the entire level folder with HTML, images, css and js in one zip archive, downloading this zip code and then unpacking it to the device. But maybe it is more efficient to download each file individually, because they can be downloaded at the same time?

This is my first iOS app, and I'm not quite sure how to do it right. Thus, the question arises: what is the best way to download the entire folder from the server asynchronously, and then start the callback when all files are downloaded (given that the user can close the application or lose the connection in the middle of the download)?

+3
source share
2 answers

3G-, ( ) , , . , . , , .

+1

, , , , . ASIHTTPRequest, " ", http://allseeing-i.com/ASIHTTPRequest/Setup-instructions

- (IBAction)downloadLevel:(NSURL *)levelURL
{
    // Assume request is a property of our controller
    // First, we'll cancel any in-progress page load
    [self.request setDelegate:nil];
    [self.request cancel];

    [self setRequest:[ASIWebPageRequest requestWithURL:levelURL]];
    [self.request setCompletionBlock:^{
        //code in here runs when the request finishes
    }];

    [self.request setFailedBlock:^{
        //code in here runs when the request fails
    }];

    // Tell the request to embed external resources directly in the page
    [self.request setUrlReplacementMode:ASIReplaceExternalResourcesWithData];

    // It is strongly recommended you use a download cache with ASIWebPageRequest
    // When using a cache, external resources are automatically stored in the cache
    // and can be pulled from the cache on subsequent page loads
    [self.request setDownloadCache:[ASIDownloadCache sharedCache]];

    // Ask the download cache for a place to store the cached data
    // This is the most efficient way for an ASIWebPageRequest to store a web page
    [self.request setDownloadDestinationPath:
     [[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:self.request]];

    [self.request startAsynchronous];
}


http://allseeing-i.com/ASIHTTPRequest/ASIWebPageRequest

http://allseeing-i.com/ASIHTTPRequest/How-to-use
.

0

All Articles