From a8210a93bb4ab13e7cbcb32518f9f0f5f737101a Mon Sep 17 00:00:00 2001 From: Eric Patey Date: Tue, 10 Jul 2012 21:12:54 -0400 Subject: [PATCH 1/4] Fix threading issue with AFNetworkActivityIndicatorManager. Changed updateNetworkActivityIndicatorVisibilityDelayed to use the main run loop rather than the current run loop for its suppression timer. Also, avoided extra dispatch to the main queue when not needed. --- AFNetworking/AFNetworkActivityIndicatorManager.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index b141323..53e388f 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -77,8 +77,8 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; // Delay hiding of activity indicator for a short interval, to avoid flickering if (![self isNetworkActivityIndicatorVisible]) { [self.activityIndicatorVisibilityTimer invalidate]; - self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO]; - [[NSRunLoop currentRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; + self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibilityOnCurrentQueue) userInfo:nil repeats:NO]; + [[NSRunLoop mainRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; } else { [self updateNetworkActivityIndicatorVisibility]; } @@ -91,10 +91,14 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; - (void)updateNetworkActivityIndicatorVisibility { dispatch_async(dispatch_get_main_queue(), ^{ - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; + [self updateNetworkActivityIndicatorVisibilityOnCurrentQueue]; }); } +- (void)updateNetworkActivityIndicatorVisibilityOnCurrentQueue { + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; +} + // Not exposed, but used if activityCount is set via KVC. - (NSInteger)activityCount { return _activityCount; From c161a420339fa680da53f80d8848165f3859ac04 Mon Sep 17 00:00:00 2001 From: "tomas.a" Date: Thu, 12 Jul 2012 17:48:12 +0200 Subject: [PATCH 2/4] Fix compiler warning in file upload progress example. Changed NSInteger to long long. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d5fb45..d207d57 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,8 @@ NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST }]; AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease]; -[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { - NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite); +[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { + NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); }]; [operation start]; ``` From 69ff0781b2e48d052cdfc6ae01747c300b2c7835 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 23 Jul 2012 12:05:21 -0700 Subject: [PATCH 3/4] Minor refactoring of changes to AFNetworkActivityIndicatorManager Slightly reducing invisibility delay --- AFNetworking/AFNetworkActivityIndicatorManager.m | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index 53e388f..5751d16 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -25,7 +25,7 @@ #import "AFHTTPRequestOperation.h" #if __IPHONE_OS_VERSION_MIN_REQUIRED -static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; +static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; @interface AFNetworkActivityIndicatorManager () @property (readwrite, atomic, assign) NSInteger activityCount; @@ -33,6 +33,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; - (void)updateNetworkActivityIndicatorVisibility; +- (void)updateNetworkActivityIndicatorVisibilityDelayed; @end @implementation AFNetworkActivityIndicatorManager @@ -77,10 +78,10 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; // Delay hiding of activity indicator for a short interval, to avoid flickering if (![self isNetworkActivityIndicatorVisible]) { [self.activityIndicatorVisibilityTimer invalidate]; - self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibilityOnCurrentQueue) userInfo:nil repeats:NO]; + self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO]; [[NSRunLoop mainRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; } else { - [self updateNetworkActivityIndicatorVisibility]; + [self performSelectorOnMainThread:@selector(updateNetworkActivityIndicatorVisibility) withObject:nil waitUntilDone:NO modes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; } } } @@ -90,12 +91,6 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; } - (void)updateNetworkActivityIndicatorVisibility { - dispatch_async(dispatch_get_main_queue(), ^{ - [self updateNetworkActivityIndicatorVisibilityOnCurrentQueue]; - }); -} - -- (void)updateNetworkActivityIndicatorVisibilityOnCurrentQueue { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; } From 9236e41850c7dbdd50924f6ed25f3d18234fee63 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 23 Jul 2012 12:15:11 -0700 Subject: [PATCH 4/4] Fixing documentation in AFHTTPClient -deletePath:... to indicate new default of encoding parameters in query string --- AFNetworking/AFHTTPClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 6d11918..043e633 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -423,7 +423,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete Creates an `AFHTTPRequestOperation` with a `DELETE` request, and enqueues it to the HTTP client's operation queue. @param path The path to be appended to the HTTP client's base URL and used as the request URL. - @param parameters The parameters to be encoded and set in the request HTTP body. + @param parameters The parameters to be encoded and appended as the query string for the request URL. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.