Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've just figured out where my problem is, but not really understand why.</p> <p>In my <code>ImageDownloader</code> class, I set up a runloop with <code>done</code> and <code>currentRunLoop</code> variables. In the main method, I have a while loop for forcing the <code>currentRunLoop</code> run.</p> <p>As I remove those "runLoop" stuffs, the app runs smoothly on both iOS6 and iOS5.</p> <p>So change the entire <code>ImageDownloader.m</code> with these lines then it works (I commented out some useless (say harmful) lines):</p> <pre><code>// // ImageLoader.m // DownloadImagesTableView // // Created by Viet Ta Quoc on 6/25/13. // Copyright (c) 2013 Viet Ta Quoc. All rights reserved. // #import "ImageDownloader.h" @implementation ImageDownloader @synthesize downloadData,delegate,queue,done,customTag; NSRunLoop *currentRunLoop; -(void)downloadImageWithURL:(NSString *)imageUrl queue:(NSOperationQueue*)opQueue andTag:(int)tag{ self.customTag= tag; self.queue = opQueue; // self.done = NO; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imageUrl] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO]; [connection start]; // currentRunLoop = [NSRunLoop currentRunLoop]; NSLog(@"Start downloading image %d...",customTag); } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSLog(@"Received response..."); downloadData=[[NSMutableData alloc] initWithLength:0]; expectedDataLength=[response expectedContentLength]; NSLog(@"Image %d size: %lld kb",customTag,[response expectedContentLength]/1024); } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ float receivedLenght = [data length]; receivedDataLength=(receivedDataLength+receivedLenght); float progress=(float)receivedDataLength/(float)expectedDataLength; [delegate updateProgess:progress andIndex:[NSIndexPath indexPathForRow:customTag-100 inSection:0]]; [self.downloadData appendData:data]; // NSLog(@"Percentage of data received of tag %d: %f %%",self.customTag,progress*100); } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ [delegate finishedDownloadingImage:downloadData andTag:customTag]; // done = YES; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Network Connection Failed?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; // NSLog(@"%@",[error debugDescription]); NSLog(@"Connection failed! Error - %@ %@",[error localizedDescription],[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); [alert show]; } -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ NSLog(@"Got here *(*&amp;(**&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;(*&amp;"); } -(void)main{ // do{ //// NSLog(@"Running....1"); // [currentRunLoop runUntilDate:[NSDate distantFuture]]; // // [currentRunLoop run]; // } while (!done); // [currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; } @end </code></pre> <p>Thank you guys for your supports.</p> <p><strong>==================================================================================</strong></p> <p><strong>P/s: for anyone who interested in this problem, I update here my entire solution: <a href="https://dl.dropboxusercontent.com/u/15628608/Public%20files/DownloadImageByOperation_new.zip" rel="nofollow">DownloadImage_Final</a></strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload