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 01-26-2012, 08:51 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 82
Guthook is on a distinguished road
Default Cancelling ASINetworkQueue

I think this should be a simple question. I've been asking a lot of these recently, but my app is almost done. Very exciting for me!

Here's the problem:
I have a ASINetworkQueue that is downloading a couple thousand map tiles in one shot from my S3 bucket. I also have a button in the main view that should cancel the queue. It works mostly, but when I tap the cancel button, it freezes the app for several seconds (up to a minute if I cancel early) while the queue calls the didFailSelector for each individual map tile that was in the queue.

Here's my code for the downloader (abbreviated where variables are declared and set):

Code:
-(void)downloadListOfItems {
    [[self queue] cancelAllOperations];
    [self setQueue:[ASINetworkQueue queue]];

    for (int i = 1; i <= numberOfBatches; i++) {
        ASIS3BucketRequest *listRequest = [ASIS3BucketRequest requestWithBucket:bucket];
[listRequest setAccessKey:accessKey];
[listRequest setSecretAccessKey:secretAccessKey];
        
        NSString *pathToBatch = [NSString stringWithFormat:@"%@/batch%i", baseDirectory, i];
[listRequest setPrefix:pathToBatch];
        [listRequest setDelegate:self];
[listRequest setDidFinishSelector:@selector(finishedDownloadingTileList:)];
[listRequest setDidFailSelector:@selector(failedDownloadingTileList:)];

        [[self queue] addOperation:listRequest];   
    }
   [self.queue go];
}


-(void)finishedDownloadingTileList:(ASIS3BucketRequest *)listRequest {

    for (ASIS3BucketObject *object in[listRequest objects]) {
        NSString *itemKey = [object key];
        
        //Split key so that we can get the item's individual name
        NSArray *array = [itemKey componentsSeparatedByString:@"/"];
        NSString *folderName = [array objectAtIndex:1];
        NSString *itemName = [array objectAtIndex:2];
        
        [self downloadOneMapTile:itemName inFolder:folderName];
        
    }

}


-(void)downloadOneMapTile: (NSString *)itemName inFolder:(NSString *)folderName {

//... set path to file in bucket and path for downloaded file

    if (!fileAlreadyExists) {
        ASIS3ObjectRequest *request = [ASIS3ObjectRequest requestWithBucket:bucket key:pathToFileInBucket];
        [request setSecretAccessKey:secretAccessKey];
        [request setAccessKey:accessKey];
        [request setDownloadDestinationPath:pathForDownloadedFile];
        
        [request setDelegate:self];
        
        [request setDidFinishSelector:@selector(tileRequestDone:)];
        [request setDidFailSelector:@selector(tileRequestFailed:)];
        
        
        [self.queue addOperation:request];

    }

}
And the cancel button code is quite simple:
Code:
[bulkDownloader.queue cancelAllOperations];
    [bulkDownloader.queue setSuspended:YES];
    [bulkDownloader.queue reset];
Thanks for any input.
Guthook is offline   Reply With Quote
Reply

Bookmarks

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: 387
10 members and 377 guests
Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

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