More progress tweaks
Cast zlib stuff to unsigned int to fix problems with uInt / UInt being a different size on different architectures Have ASINetworkQueue reset progress in when setting progress delegates Stop calling [super initialize] in ASIHTTPRequest iPhone sample app now uses the same images as Mac sample in the queue example
Showing
7 changed files
with
74 additions
and
58 deletions
@@ -216,6 +216,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -216,6 +216,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
216 | // HTTP status code, eg: 200 = OK, 404 = Not found etc | 216 | // HTTP status code, eg: 200 = OK, 404 = Not found etc |
217 | int responseStatusCode; | 217 | int responseStatusCode; |
218 | 218 | ||
219 | + // Description of the HTTP status code | ||
219 | NSString *responseStatusMessage; | 220 | NSString *responseStatusMessage; |
220 | 221 | ||
221 | // Size of the response | 222 | // Size of the response |
@@ -471,6 +472,8 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -471,6 +472,8 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
471 | // Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView) | 472 | // Helper method for interacting with progress indicators to abstract the details of different APIS (NSProgressIndicator and UIProgressView) |
472 | + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total; | 473 | + (void)updateProgressIndicator:(id)indicator withProgress:(unsigned long long)progress ofTotal:(unsigned long long)total; |
473 | 474 | ||
475 | +// Helper method used for performing invocations on the main thread (used for progress) | ||
476 | ++ (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object amount:(void *)amount; | ||
474 | 477 | ||
475 | #pragma mark handling request complete / failure | 478 | #pragma mark handling request complete / failure |
476 | 479 |
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | 23 | ||
24 | 24 | ||
25 | // Automatically set on build | 25 | // Automatically set on build |
26 | -NSString *ASIHTTPRequestVersion = @"v1.6.1-13 2010-04-14"; | 26 | +NSString *ASIHTTPRequestVersion = @"v1.6.1-14 2010-04-14"; |
27 | 27 | ||
28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
29 | 29 | ||
@@ -141,9 +141,6 @@ static BOOL isiPhoneOS2; | @@ -141,9 +141,6 @@ static BOOL isiPhoneOS2; | ||
141 | 141 | ||
142 | - (void)updateStatus:(NSTimer*)timer; | 142 | - (void)updateStatus:(NSTimer*)timer; |
143 | 143 | ||
144 | -// Helper method used for performing invocations on the main thread | ||
145 | -+ (void)performSelector:(SEL)selector onTarget:(id)target withObject:(id)object amount:(void *)amount; | ||
146 | - | ||
147 | #if TARGET_OS_IPHONE | 144 | #if TARGET_OS_IPHONE |
148 | + (void)registerForNetworkReachabilityNotifications; | 145 | + (void)registerForNetworkReachabilityNotifications; |
149 | + (void)unsubscribeFromNetworkReachabilityNotifications; | 146 | + (void)unsubscribeFromNetworkReachabilityNotifications; |
@@ -220,7 +217,6 @@ static BOOL isiPhoneOS2; | @@ -220,7 +217,6 @@ static BOOL isiPhoneOS2; | ||
220 | isiPhoneOS2 = NO; | 217 | isiPhoneOS2 = NO; |
221 | #endif | 218 | #endif |
222 | } | 219 | } |
223 | - [super initialize]; | ||
224 | } | 220 | } |
225 | 221 | ||
226 | 222 | ||
@@ -1034,12 +1030,16 @@ static BOOL isiPhoneOS2; | @@ -1034,12 +1030,16 @@ static BOOL isiPhoneOS2; | ||
1034 | 1030 | ||
1035 | [[self cancelledLock] unlock]; | 1031 | [[self cancelledLock] unlock]; |
1036 | 1032 | ||
1037 | - if ([self shouldResetProgressIndicators]) { | 1033 | + if (![self mainRequest] && [self shouldResetProgressIndicators]) { |
1038 | if ([self showAccurateProgress]) { | 1034 | if ([self showAccurateProgress]) { |
1039 | [self incrementUploadSizeBy:[self postLength]]; | 1035 | [self incrementUploadSizeBy:[self postLength]]; |
1040 | } else { | 1036 | } else { |
1041 | [self incrementUploadSizeBy:1]; | 1037 | [self incrementUploadSizeBy:1]; |
1042 | } | 1038 | } |
1039 | + [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:0 ofTotal:1]; | ||
1040 | + if (![self partialDownloadSize]) { | ||
1041 | + [ASIHTTPRequest updateProgressIndicator:[self downloadProgressDelegate] withProgress:0 ofTotal:1]; | ||
1042 | + } | ||
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | 1045 | ||
@@ -1057,8 +1057,6 @@ static BOOL isiPhoneOS2; | @@ -1057,8 +1057,6 @@ static BOOL isiPhoneOS2; | ||
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | - | ||
1061 | - | ||
1062 | - (void)setStatusTimer:(NSTimer *)timer | 1060 | - (void)setStatusTimer:(NSTimer *)timer |
1063 | { | 1061 | { |
1064 | [self retain]; | 1062 | [self retain]; |
@@ -1361,7 +1359,7 @@ static BOOL isiPhoneOS2; | @@ -1361,7 +1359,7 @@ static BOOL isiPhoneOS2; | ||
1361 | 1359 | ||
1362 | [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self queue] withObject:self amount:&value]; | 1360 | [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self queue] withObject:self amount:&value]; |
1363 | [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self uploadProgressDelegate] withObject:self amount:&value]; | 1361 | [ASIHTTPRequest performSelector:@selector(request:didSendBytes:) onTarget:[self uploadProgressDelegate] withObject:self amount:&value]; |
1364 | - [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:[self totalBytesSent] ofTotal:[self postLength]]; | 1362 | + [ASIHTTPRequest updateProgressIndicator:[self uploadProgressDelegate] withProgress:[self totalBytesSent]-[self uploadBufferSize] ofTotal:[self postLength]]; |
1365 | } | 1363 | } |
1366 | 1364 | ||
1367 | 1365 | ||
@@ -1633,7 +1631,7 @@ static BOOL isiPhoneOS2; | @@ -1633,7 +1631,7 @@ static BOOL isiPhoneOS2; | ||
1633 | } else { | 1631 | } else { |
1634 | [theRequest setContentLength:length]; | 1632 | [theRequest setContentLength:length]; |
1635 | if ([self showAccurateProgress] && [self shouldResetProgressIndicators]) { | 1633 | if ([self showAccurateProgress] && [self shouldResetProgressIndicators]) { |
1636 | - [theRequest incrementDownloadSizeBy:[self contentLength]+[self partialDownloadSize]]; | 1634 | + [theRequest incrementDownloadSizeBy:[theRequest contentLength]+[theRequest partialDownloadSize]]; |
1637 | } | 1635 | } |
1638 | } | 1636 | } |
1639 | 1637 | ||
@@ -3010,7 +3008,7 @@ static BOOL isiPhoneOS2; | @@ -3010,7 +3008,7 @@ static BOOL isiPhoneOS2; | ||
3010 | 3008 | ||
3011 | z_stream strm; | 3009 | z_stream strm; |
3012 | strm.next_in = (Bytef *)[compressedData bytes]; | 3010 | strm.next_in = (Bytef *)[compressedData bytes]; |
3013 | - strm.avail_in = (UInt)[compressedData length]; | 3011 | + strm.avail_in = (unsigned int)[compressedData length]; |
3014 | strm.total_out = 0; | 3012 | strm.total_out = 0; |
3015 | strm.zalloc = Z_NULL; | 3013 | strm.zalloc = Z_NULL; |
3016 | strm.zfree = Z_NULL; | 3014 | strm.zfree = Z_NULL; |
@@ -3023,7 +3021,7 @@ static BOOL isiPhoneOS2; | @@ -3023,7 +3021,7 @@ static BOOL isiPhoneOS2; | ||
3023 | [decompressed increaseLengthBy: half_length]; | 3021 | [decompressed increaseLengthBy: half_length]; |
3024 | } | 3022 | } |
3025 | strm.next_out = [decompressed mutableBytes] + strm.total_out; | 3023 | strm.next_out = [decompressed mutableBytes] + strm.total_out; |
3026 | - strm.avail_out = (UInt)([decompressed length] - strm.total_out); | 3024 | + strm.avail_out = (unsigned int)([decompressed length] - strm.total_out); |
3027 | 3025 | ||
3028 | // Inflate another chunk. | 3026 | // Inflate another chunk. |
3029 | status = inflate (&strm, Z_SYNC_FLUSH); | 3027 | status = inflate (&strm, Z_SYNC_FLUSH); |
@@ -3098,7 +3096,7 @@ static BOOL isiPhoneOS2; | @@ -3098,7 +3096,7 @@ static BOOL isiPhoneOS2; | ||
3098 | 3096 | ||
3099 | /* decompress until deflate stream ends or end of file */ | 3097 | /* decompress until deflate stream ends or end of file */ |
3100 | do { | 3098 | do { |
3101 | - strm.avail_in = (UInt)fread(in, 1, CHUNK, source); | 3099 | + strm.avail_in = (unsigned int)fread(in, 1, CHUNK, source); |
3102 | if (ferror(source)) { | 3100 | if (ferror(source)) { |
3103 | (void)inflateEnd(&strm); | 3101 | (void)inflateEnd(&strm); |
3104 | return Z_ERRNO; | 3102 | return Z_ERRNO; |
@@ -3152,7 +3150,7 @@ static BOOL isiPhoneOS2; | @@ -3152,7 +3150,7 @@ static BOOL isiPhoneOS2; | ||
3152 | strm.opaque = Z_NULL; | 3150 | strm.opaque = Z_NULL; |
3153 | strm.total_out = 0; | 3151 | strm.total_out = 0; |
3154 | strm.next_in=(Bytef *)[uncompressedData bytes]; | 3152 | strm.next_in=(Bytef *)[uncompressedData bytes]; |
3155 | - strm.avail_in = (UInt)[uncompressedData length]; | 3153 | + strm.avail_in = (unsigned int)[uncompressedData length]; |
3156 | 3154 | ||
3157 | // Compresssion Levels: | 3155 | // Compresssion Levels: |
3158 | // Z_NO_COMPRESSION | 3156 | // Z_NO_COMPRESSION |
@@ -3170,7 +3168,7 @@ static BOOL isiPhoneOS2; | @@ -3170,7 +3168,7 @@ static BOOL isiPhoneOS2; | ||
3170 | [compressed increaseLengthBy: 16384]; | 3168 | [compressed increaseLengthBy: 16384]; |
3171 | 3169 | ||
3172 | strm.next_out = [compressed mutableBytes] + strm.total_out; | 3170 | strm.next_out = [compressed mutableBytes] + strm.total_out; |
3173 | - strm.avail_out = (UInt)([compressed length] - strm.total_out); | 3171 | + strm.avail_out = (unsigned int)([compressed length] - strm.total_out); |
3174 | 3172 | ||
3175 | deflate(&strm, Z_FINISH); | 3173 | deflate(&strm, Z_FINISH); |
3176 | 3174 | ||
@@ -3231,7 +3229,7 @@ static BOOL isiPhoneOS2; | @@ -3231,7 +3229,7 @@ static BOOL isiPhoneOS2; | ||
3231 | 3229 | ||
3232 | /* compress until end of file */ | 3230 | /* compress until end of file */ |
3233 | do { | 3231 | do { |
3234 | - strm.avail_in = (UInt)fread(in, 1, CHUNK, source); | 3232 | + strm.avail_in = (unsigned int)fread(in, 1, CHUNK, source); |
3235 | if (ferror(source)) { | 3233 | if (ferror(source)) { |
3236 | (void)deflateEnd(&strm); | 3234 | (void)deflateEnd(&strm); |
3237 | return Z_ERRNO; | 3235 | return Z_ERRNO; |
@@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
11 | 11 | ||
12 | // Private stuff | 12 | // Private stuff |
13 | @interface ASINetworkQueue () | 13 | @interface ASINetworkQueue () |
14 | + - (void)resetProgressDelegate:(id)progressDelegate; | ||
14 | @property (assign) int requestsCount; | 15 | @property (assign) int requestsCount; |
15 | @end | 16 | @end |
16 | 17 | ||
@@ -104,36 +105,35 @@ | @@ -104,36 +105,35 @@ | ||
104 | - (void)setUploadProgressDelegate:(id)newDelegate | 105 | - (void)setUploadProgressDelegate:(id)newDelegate |
105 | { | 106 | { |
106 | uploadProgressDelegate = newDelegate; | 107 | uploadProgressDelegate = newDelegate; |
108 | + [self resetProgressDelegate:newDelegate]; | ||
107 | 109 | ||
108 | -#if !TARGET_OS_IPHONE | ||
109 | - // If the uploadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews | ||
110 | - SEL selector = @selector(setMaxValue:); | ||
111 | - if ([[self uploadProgressDelegate] respondsToSelector:selector]) { | ||
112 | - double max = 1.0; | ||
113 | - NSMethodSignature *signature = [[[self uploadProgressDelegate] class] instanceMethodSignatureForSelector:selector]; | ||
114 | - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | ||
115 | - [invocation setSelector:selector]; | ||
116 | - [invocation setArgument:&max atIndex:2]; | ||
117 | - [invocation invokeWithTarget:[self uploadProgressDelegate]]; | ||
118 | - } | ||
119 | -#endif | ||
120 | } | 110 | } |
121 | 111 | ||
122 | - | ||
123 | - (void)setDownloadProgressDelegate:(id)newDelegate | 112 | - (void)setDownloadProgressDelegate:(id)newDelegate |
124 | { | 113 | { |
125 | downloadProgressDelegate = newDelegate; | 114 | downloadProgressDelegate = newDelegate; |
115 | + [self resetProgressDelegate:newDelegate]; | ||
116 | +} | ||
126 | 117 | ||
118 | +- (void)resetProgressDelegate:(id)progressDelegate | ||
119 | +{ | ||
127 | #if !TARGET_OS_IPHONE | 120 | #if !TARGET_OS_IPHONE |
128 | - // If the downloadProgressDelegate is an NSProgressIndicator, we set it's MaxValue to 1.0 so we can treat it similarly to UIProgressViews | 121 | + // If the uploadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can treat it similarly to UIProgressViews |
129 | SEL selector = @selector(setMaxValue:); | 122 | SEL selector = @selector(setMaxValue:); |
130 | - if ([[self downloadProgressDelegate] respondsToSelector:selector]) { | 123 | + if ([progressDelegate respondsToSelector:selector]) { |
131 | double max = 1.0; | 124 | double max = 1.0; |
132 | - NSMethodSignature *signature = [[[self downloadProgressDelegate] class] instanceMethodSignatureForSelector:selector]; | 125 | + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&max]; |
133 | - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | 126 | + } |
134 | - [invocation setSelector:@selector(setMaxValue:)]; | 127 | + selector = @selector(setDoubleValue:); |
135 | - [invocation setArgument:&max atIndex:2]; | 128 | + if ([progressDelegate respondsToSelector:selector]) { |
136 | - [invocation invokeWithTarget:[self downloadProgressDelegate]]; | 129 | + double value = 0.0; |
130 | + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&value]; | ||
131 | + } | ||
132 | +#else | ||
133 | + SEL selector = @selector(setProgress:); | ||
134 | + if ([progressDelegate respondsToSelector:selector]) { | ||
135 | + float value = 0.0f; | ||
136 | + [ASIHTTPRequest performSelector:selector onTarget:progressDelegate withObject:nil amount:&value]; | ||
137 | } | 137 | } |
138 | #endif | 138 | #endif |
139 | } | 139 | } |
@@ -177,6 +177,10 @@ | @@ -177,6 +177,10 @@ | ||
177 | ASIHTTPRequest *HEADRequest = [request HEADRequest]; | 177 | ASIHTTPRequest *HEADRequest = [request HEADRequest]; |
178 | [self addHEADOperation:HEADRequest]; | 178 | [self addHEADOperation:HEADRequest]; |
179 | 179 | ||
180 | + if ([request shouldResetProgressIndicators]) { | ||
181 | + [self resetProgressDelegate:[request downloadProgressDelegate]]; | ||
182 | + } | ||
183 | + | ||
180 | //Tell the request not to reset the progress indicator when it gets a content-length, as we will get the length from the HEAD request | 184 | //Tell the request not to reset the progress indicator when it gets a content-length, as we will get the length from the HEAD request |
181 | [request setShouldResetProgressIndicators:NO]; | 185 | [request setShouldResetProgressIndicators:NO]; |
182 | 186 | ||
@@ -186,6 +190,12 @@ | @@ -186,6 +190,12 @@ | ||
186 | } else if (uploadProgressDelegate) { | 190 | } else if (uploadProgressDelegate) { |
187 | [request buildPostBody]; | 191 | [request buildPostBody]; |
188 | [self setTotalBytesToUpload:[self totalBytesToUpload]+[request postLength]]; | 192 | [self setTotalBytesToUpload:[self totalBytesToUpload]+[request postLength]]; |
193 | + | ||
194 | + | ||
195 | + if ([request shouldResetProgressIndicators]) { | ||
196 | + [self resetProgressDelegate:[request uploadProgressDelegate]]; | ||
197 | + } | ||
198 | + | ||
189 | [request setShouldResetProgressIndicators:NO]; | 199 | [request setShouldResetProgressIndicators:NO]; |
190 | } | 200 | } |
191 | } | 201 | } |
@@ -49,7 +49,7 @@ | @@ -49,7 +49,7 @@ | ||
49 | 49 | ||
50 | - (IBAction)fetchThreeImages:(id)sender; | 50 | - (IBAction)fetchThreeImages:(id)sender; |
51 | 51 | ||
52 | -- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request; | 52 | + |
53 | - (IBAction)dismissAuthSheet:(id)sender; | 53 | - (IBAction)dismissAuthSheet:(id)sender; |
54 | - (IBAction)fetchTopSecretInformation:(id)sender; | 54 | - (IBAction)fetchTopSecretInformation:(id)sender; |
55 | 55 | ||
@@ -57,16 +57,6 @@ | @@ -57,16 +57,6 @@ | ||
57 | 57 | ||
58 | - (IBAction)throttleBandwidth:(id)sender; | 58 | - (IBAction)throttleBandwidth:(id)sender; |
59 | 59 | ||
60 | -- (void)updateBandwidthUsageIndicator; | ||
61 | -- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request; | ||
62 | -- (void)URLFetchWithProgressFailed:(ASIHTTPRequest *)request; | ||
63 | -- (void)imageFetch1Complete:(ASIHTTPRequest *)request; | ||
64 | -- (void)imageFetch2Complete:(ASIHTTPRequest *)request; | ||
65 | -- (void)imageFetch3Complete:(ASIHTTPRequest *)request; | ||
66 | -- (void)topSecretFetchComplete:(ASIHTTPRequest *)request; | ||
67 | -- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; | ||
68 | -- (void)postFinished:(ASIHTTPRequest *)request; | ||
69 | -- (void)postFailed:(ASIHTTPRequest *)request; | ||
70 | 60 | ||
71 | @property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest; | 61 | @property (retain, nonatomic) ASIHTTPRequest *bigFetchRequest; |
72 | @end | 62 | @end |
@@ -10,6 +10,19 @@ | @@ -10,6 +10,19 @@ | ||
10 | #import "ASIFormDataRequest.h" | 10 | #import "ASIFormDataRequest.h" |
11 | #import "ASINetworkQueue.h" | 11 | #import "ASINetworkQueue.h" |
12 | 12 | ||
13 | +@interface AppDelegate () | ||
14 | +- (void)updateBandwidthUsageIndicator; | ||
15 | +- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request; | ||
16 | +- (void)URLFetchWithProgressFailed:(ASIHTTPRequest *)request; | ||
17 | +- (void)imageFetch1Complete:(ASIHTTPRequest *)request; | ||
18 | +- (void)imageFetch2Complete:(ASIHTTPRequest *)request; | ||
19 | +- (void)imageFetch3Complete:(ASIHTTPRequest *)request; | ||
20 | +- (void)topSecretFetchComplete:(ASIHTTPRequest *)request; | ||
21 | +- (void)authSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; | ||
22 | +- (void)postFinished:(ASIHTTPRequest *)request; | ||
23 | +- (void)postFailed:(ASIHTTPRequest *)request; | ||
24 | +@end | ||
25 | + | ||
13 | @implementation AppDelegate | 26 | @implementation AppDelegate |
14 | 27 | ||
15 | - (id)init | 28 | - (id)init |
@@ -79,7 +92,7 @@ | @@ -79,7 +92,7 @@ | ||
79 | [startButton setAction:@selector(stopURLFetchWithProgress:)]; | 92 | [startButton setAction:@selector(stopURLFetchWithProgress:)]; |
80 | 93 | ||
81 | // Stop any other requests | 94 | // Stop any other requests |
82 | - [networkQueue cancelAllOperations]; | 95 | + [networkQueue reset]; |
83 | 96 | ||
84 | [self setBigFetchRequest:[[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/redirect_resume"]] autorelease]]; | 97 | [self setBigFetchRequest:[[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/redirect_resume"]] autorelease]]; |
85 | [[self bigFetchRequest] setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"The Great American Novel.txt"]]; | 98 | [[self bigFetchRequest] setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"The Great American Novel.txt"]]; |
@@ -116,8 +129,7 @@ | @@ -116,8 +129,7 @@ | ||
116 | [imageView2 setImage:nil]; | 129 | [imageView2 setImage:nil]; |
117 | [imageView3 setImage:nil]; | 130 | [imageView3 setImage:nil]; |
118 | 131 | ||
119 | - [networkQueue cancelAllOperations]; | 132 | + [networkQueue reset]; |
120 | - [networkQueue setRequestDidFinishSelector:NULL]; | ||
121 | [networkQueue setDownloadProgressDelegate:progressIndicator]; | 133 | [networkQueue setDownloadProgressDelegate:progressIndicator]; |
122 | [networkQueue setDelegate:self]; | 134 | [networkQueue setDelegate:self]; |
123 | [networkQueue setShowAccurateProgress:([showAccurateProgress state] == NSOnState)]; | 135 | [networkQueue setShowAccurateProgress:([showAccurateProgress state] == NSOnState)]; |
@@ -192,7 +204,7 @@ | @@ -192,7 +204,7 @@ | ||
192 | 204 | ||
193 | - (IBAction)fetchTopSecretInformation:(id)sender | 205 | - (IBAction)fetchTopSecretInformation:(id)sender |
194 | { | 206 | { |
195 | - [networkQueue cancelAllOperations]; | 207 | + [networkQueue reset]; |
196 | 208 | ||
197 | [progressIndicator setDoubleValue:0]; | 209 | [progressIndicator setDoubleValue:0]; |
198 | 210 | ||
@@ -268,7 +280,7 @@ | @@ -268,7 +280,7 @@ | ||
268 | [data writeToFile:path atomically:NO]; | 280 | [data writeToFile:path atomically:NO]; |
269 | 281 | ||
270 | 282 | ||
271 | - [networkQueue cancelAllOperations]; | 283 | + [networkQueue reset]; |
272 | [networkQueue setShowAccurateProgress:YES]; | 284 | [networkQueue setShowAccurateProgress:YES]; |
273 | [networkQueue setUploadProgressDelegate:progressIndicator]; | 285 | [networkQueue setUploadProgressDelegate:progressIndicator]; |
274 | [networkQueue setRequestDidFailSelector:@selector(postFailed:)]; | 286 | [networkQueue setRequestDidFailSelector:@selector(postFailed:)]; |
@@ -31,13 +31,16 @@ | @@ -31,13 +31,16 @@ | ||
31 | [networkQueue setDelegate:self]; | 31 | [networkQueue setDelegate:self]; |
32 | 32 | ||
33 | ASIHTTPRequest *request; | 33 | ASIHTTPRequest *request; |
34 | - request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/logo.png"]]; | 34 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]]; |
35 | + [request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"1.png"]]; | ||
35 | [networkQueue addOperation:request]; | 36 | [networkQueue addOperation:request]; |
36 | 37 | ||
37 | - request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/trailsnetwork.png"]] autorelease]; | 38 | + request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease]; |
39 | + [request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"2.png"]]; | ||
38 | [networkQueue addOperation:request]; | 40 | [networkQueue addOperation:request]; |
39 | 41 | ||
40 | - request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/sharedspace20.png"]] autorelease]; | 42 | + request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease]; |
43 | + [request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"3.png"]]; | ||
41 | [networkQueue addOperation:request]; | 44 | [networkQueue addOperation:request]; |
42 | 45 | ||
43 | [networkQueue go]; | 46 | [networkQueue go]; |
@@ -46,7 +49,7 @@ | @@ -46,7 +49,7 @@ | ||
46 | 49 | ||
47 | - (void)imageFetchComplete:(ASIHTTPRequest *)request | 50 | - (void)imageFetchComplete:(ASIHTTPRequest *)request |
48 | { | 51 | { |
49 | - UIImage *img = [UIImage imageWithData:[request responseData]]; | 52 | + UIImage *img = [UIImage imageWithContentsOfFile:[request downloadDestinationPath]]; |
50 | if (img) { | 53 | if (img) { |
51 | if ([imageView1 image]) { | 54 | if ([imageView1 image]) { |
52 | if ([imageView2 image]) { | 55 | if ([imageView2 image]) { |
@@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES | @@ -13,11 +13,11 @@ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES | ||
13 | GCC_WARN_ABOUT_RETURN_TYPE = YES | 13 | GCC_WARN_ABOUT_RETURN_TYPE = YES |
14 | //GCC_WARN_MISSING_PARENTHESES = YES | 14 | //GCC_WARN_MISSING_PARENTHESES = YES |
15 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES | 15 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES |
16 | -GCC_WARN_ABOUT_MISSING_NEWLINE = YES | 16 | +//GCC_WARN_ABOUT_MISSING_NEWLINE = YES |
17 | GCC_WARN_SIGN_COMPARE = YES | 17 | GCC_WARN_SIGN_COMPARE = YES |
18 | GCC_WARN_STRICT_SELECTOR_MATCH = missing value | 18 | GCC_WARN_STRICT_SELECTOR_MATCH = missing value |
19 | GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES | 19 | GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES |
20 | -GCC_WARN_UNDECLARED_SELECTOR = YES | 20 | +//GCC_WARN_UNDECLARED_SELECTOR = YES |
21 | GCC_WARN_UNUSED_FUNCTION = YES | 21 | GCC_WARN_UNUSED_FUNCTION = YES |
22 | GCC_WARN_UNUSED_LABEL = YES | 22 | GCC_WARN_UNUSED_LABEL = YES |
23 | GCC_WARN_UNUSED_VALUE = YES | 23 | GCC_WARN_UNUSED_VALUE = YES |
-
Please register or login to post a comment