Afnetworking: Network Activity Indicator not working after 2.x - > 3.x

Created on 16 Mar 2016  路  10Comments  路  Source: AFNetworking/AFNetworking

Hey all,

I searched the existing issues but I couldn't find a solution to this.

I have enabled the AFNetworkActivityIndicatorManager

[AFNetworkActivityIndicatorManager sharedManager].enabled = YES; [AFNetworkActivityIndicatorManager sharedManager].activationDelay = 0;

and my requests are executed as such :

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", nil];
[manager.requestSerializer setTimeoutInterval:45];

[httpManager POST:@"urlhere" parameters:@{"param1":@"value1"} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

}];

I have multiple requests that do take a while to execute, and I would expect the activity indicator to show up (which it did when using 2.x), but after upgrading to 3 it no longer shows.

I put debug points in the AFNetworkActivityIndicatorManager and it looks like the
networkRequestDidFinish:
is called, which is where it turns off the activity indicator (decrement etc..), but the
networkRequestDidStart:
is never called, which is where it increments the counter and is supposed to turn on the indicator.

Any idea why this would be happening?

bug

Most helpful comment

I have the same issue, but I simply resolved with following code.
[AFNetworkActivityIndicatorManager sharedManager].activationDelay = 0;

Do you have any sample Xcode project to reproduce this issue ?

All 10 comments

Traced it back to AFURLSessionManager , and I was able to confirm the notification is fired in here

- (void)af_resume {
    NSAssert([self respondsToSelector:@selector(state)], @"Does not respond to state");
    NSURLSessionTaskState state = [self state];
    [self af_resume];

    if (state != NSURLSessionTaskStateRunning) {
        [[NSNotificationCenter defaultCenter] postNotificationName:AFNSURLSessionTaskDidResumeNotification object:self];
    }
}

But the listener for that notification is never called (Neither taskDidResume or taskDidSuspend)

- (void)addNotificationObserverForTask:(NSURLSessionTask *)task {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidResume:) name:AFNSURLSessionTaskDidResumeNotification object:task];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidSuspend:) name:AFNSURLSessionTaskDidSuspendNotification object:task];
}
- (void)taskDidResume:(NSNotification *)notification {
    NSURLSessionTask *task = notification.object;
    if ([task respondsToSelector:@selector(taskDescription)]) {
        if ([task.taskDescription isEqualToString:self.taskDescriptionForSessionTasks]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidResumeNotification object:task];
            });
        }
    }
}
- (void)taskDidSuspend:(NSNotification *)notification {
    NSURLSessionTask *task = notification.object;
    if ([task respondsToSelector:@selector(taskDescription)]) {
        if ([task.taskDescription isEqualToString:self.taskDescriptionForSessionTasks]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidSuspendNotification object:task];
            });
        }
    }
}

I can also confirm that the Notification listeners are not being removed by the dealloc, but by the task actually ending.

- (void)URLSession:(NSURLSession *)session
              task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error
{
    AFURLSessionManagerTaskDelegate *delegate = [self delegateForTask:task];

    // delegate may be nil when completing a task in the background
    if (delegate) {
        [delegate URLSession:session task:task didCompleteWithError:error];

        [self removeDelegateForTask:task];
    }

    if (self.taskDidComplete) {
        self.taskDidComplete(session, task, error);
    }
}

The code above is called before any of the taskDidResume or taskDidSuspend get called..

If I replace

- (void)addNotificationObserverForTask:(NSURLSessionTask *)task {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidResume:) name:AFNSURLSessionTaskDidResumeNotification object:task];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidSuspend:) name:AFNSURLSessionTaskDidSuspendNotification object:task];
}

With (object:nil instead of object:task):

- (void)addNotificationObserverForTask:(NSURLSessionTask *)task {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidResume:) name:AFNSURLSessionTaskDidResumeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidSuspend:) name:AFNSURLSessionTaskDidSuspendNotification object:nil];
}

It now works. Any ideas?

Same issue here, any idea?

Tried the fix from @senatorsfc but the loading never gets dismissed.

@ipodishima I ended up adding a global listener on the app delegate for the notifications and forwarding the notifications myself. Seems to be working so far as a work-around.. but I have no idea why the built in NetworkActivityManager from AFNetworking is not working.

#define AFNetworkingTaskStarted @"com.alamofire.networking.nsurlsessiontask.resume"
#define AFNetworkingTaskSuspended @"com.alamofire.networking.nsurlsessiontask.suspend"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNetTaskSuspended:) name:AFNetworkingTaskSuspended object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNetTaskStarted:) name:AFNetworkingTaskStarted object:nil];
-(void)onNetTaskStarted:(NSNotification*)notification {
    NSURLSessionTask *task = notification.object;

    dispatch_async(dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidResumeNotification object:task];
    });
}

-(void)onNetTaskSuspended:(NSNotification*)notification {
    NSURLSessionTask *task = notification.object;

    dispatch_async(dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidSuspendNotification object:task];
    });
}

Thanks for the detailed notes here @senatorsfc! I'll see what I can dig into here off of your test cases.

I have the same issue, but I simply resolved with following code.
[AFNetworkActivityIndicatorManager sharedManager].activationDelay = 0;

Do you have any sample Xcode project to reproduce this issue ?

I can reproduce this bug only release build.

NSNotificationCenter addObserver:selector:name:object:<Not nil value>]; doesn't seem to be work in only release build. I don't know whether this is iOS's bug or not.

I try to fix this bug on my fork.
https://github.com/kenmaz/AFNetworking/commit/39d75f6504e4f7f36a381a8f07dd7433ecacfc16

`

Although our symptom is different, I wonder if this is related to what @senatorsfc found out ...

In our case, the Network Activity Indicator never goes away. We tried with AFN 2.5.1, 2.6.1 and 2.6.3. but all produce the same result - we had never used the network activity indicator until now.

From debugging, it seems like AFNetworkActivityIndicatorManager -incrementActivityCount is called twice for the same task via the AFNetworkingTaskDidResumeNotification fired from AFURLSessionManager -taskDidResume:. However, AFNetworkActivityIndicatorManager -decrementActivityCount is only called once. We tried with and without network and the symptom is the same.

Here is what we record on the LLDB console:

Suggestions?

>>> -multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:
* thread #1: tid = 0x95bc4d, 0x0047cf02 AFNetworking`-[AFHTTPRequestSerializer multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:](self=0x175324c0, _cmd="multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:", method=@"POST", URLString=@"xxxxxx", parameters=2 key/value pairs, block=0x00440a7c, error=domain: class name = __NSStackBlock__ - code: 0) + 2298 at AFURLRequestSerialization.m:451, stop reason = breakpoint 16.1
  * frame #0: 0x0047cf02 AFNetworking`-[AFHTTPRequestSerializer multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:](self=0x175324c0, _cmd="multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:", method=@"POST", URLString=@"xxxxxx", parameters=2 key/value pairs, block=0x00440a7c, error=domain: class name = __NSStackBlock__ - code: 0) + 2298 at AFURLRequestSerialization.m:451
    frame #1: 0x0046c10a AFNetworking`-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:](self=0x1764e360, _cmd="POST:parameters:constructingBodyWithBlock:success:failure:", URLString=@"xxxxxx", parameters=2 key/value pairs, block=0x00440a7c, success=0x00440a50, failure=0x00440a24) + 514 at AFHTTPSessionManager.m:156
    frame #2: 0x001bdf3c xxxxxx`...
    frame #3: 0x001799c8 xxxxxx`...
    frame #4: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #5: 0x0052d8e8 libdispatch.dylib`_dispatch_after_timer_callback + 108
    frame #6: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #7: 0x0053756c libdispatch.dylib`_dispatch_source_latch_and_call + 2256
    frame #8: 0x00525b42 libdispatch.dylib`_dispatch_source_invoke + 738
    frame #9: 0x00528156 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 402
    frame #10: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #11: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #12: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #13: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #14: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #15: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #16: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #17: 0x20768872 libdyld.dylib`start + 2
>>> -taskDidResume:
* thread #1: tid = 0x95bc4d, 0x0048e702 AFNetworking`-[AFURLSessionManager taskDidResume:](self=0x1764e360, _cmd="taskDidResume:", notification=@"com.alamofire.networking.nsurlsessiontask.resume") + 50 at AFURLSessionManager.m:484, queue = 'com.apple.main-thread', stop reason = breakpoint 13.1
  * frame #0: 0x0048e702 AFNetworking`-[AFURLSessionManager taskDidResume:](self=0x1764e360, _cmd="taskDidResume:", notification=@"com.alamofire.networking.nsurlsessiontask.resume") + 50 at AFURLSessionManager.m:484
    frame #1: 0x20b5f344 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #2: 0x20b5ed52 CoreFoundation`_CFXRegistrationPost + 398
    frame #3: 0x20b5eb28 CoreFoundation`___CFXNotificationPost_block_invoke + 40
    frame #4: 0x20bb5f62 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1334
    frame #5: 0x20abe0ea CoreFoundation`_CFXNotificationPost + 486
    frame #6: 0x21303b16 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    frame #7: 0x2130864a Foundation`-[NSNotificationCenter postNotificationName:object:] + 30
    frame #8: 0x0048d822 AFNetworking`-[_AFURLSessionTaskSwizzling af_resume](self=0x18fecae0, _cmd="resume") + 506 at AFURLSessionManager.m:376
    frame #9: 0x0046c38a AFNetworking`-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:](self=0x1764e360, _cmd="POST:parameters:constructingBodyWithBlock:success:failure:", URLString=@"xxxxxx", parameters=2 key/value pairs, block=0x00440a7c, success=0x00440a50, failure=0x00440a24) + 1154 at AFHTTPSessionManager.m:182
    frame #10: 0x001bdf3c xxxxxx`...
    frame #11: 0x001799c8 xxxxxx`...
    frame #12: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #13: 0x0052d8e8 libdispatch.dylib`_dispatch_after_timer_callback + 108
    frame #14: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #15: 0x0053756c libdispatch.dylib`_dispatch_source_latch_and_call + 2256
    frame #16: 0x00525b42 libdispatch.dylib`_dispatch_source_invoke + 738
    frame #17: 0x00528156 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 402
    frame #18: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #19: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #20: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #21: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #22: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #23: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #24: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #25: 0x20768872 libdyld.dylib`start + 2
>>> -taskDidResume:
* thread #1: tid = 0x95bc4d, 0x0048e702 AFNetworking`-[AFURLSessionManager taskDidResume:](self=0x1764e360, _cmd="taskDidResume:", notification=@"com.alamofire.networking.nsurlsessiontask.resume") + 50 at AFURLSessionManager.m:484, queue = 'com.apple.main-thread', stop reason = breakpoint 13.1
  * frame #0: 0x0048e702 AFNetworking`-[AFURLSessionManager taskDidResume:](self=0x1764e360, _cmd="taskDidResume:", notification=@"com.alamofire.networking.nsurlsessiontask.resume") + 50 at AFURLSessionManager.m:484
    frame #1: 0x20b5f344 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #2: 0x20b5ed52 CoreFoundation`_CFXRegistrationPost + 398
    frame #3: 0x20b5eb28 CoreFoundation`___CFXNotificationPost_block_invoke + 40
    frame #4: 0x20bb5f62 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1334
    frame #5: 0x20abe0ea CoreFoundation`_CFXNotificationPost + 486
    frame #6: 0x21303b16 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    frame #7: 0x2130864a Foundation`-[NSNotificationCenter postNotificationName:object:] + 30
    frame #8: 0x0048d822 AFNetworking`-[_AFURLSessionTaskSwizzling af_resume](self=0x18fecae0, _cmd="resume") + 506 at AFURLSessionManager.m:376
    frame #9: 0x0046c38a AFNetworking`-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:](self=0x1764e360, _cmd="POST:parameters:constructingBodyWithBlock:success:failure:", URLString=@"xxxxxx", parameters=2 key/value pairs, block=0x00440a7c, success=0x00440a50, failure=0x00440a24) + 1154 at AFHTTPSessionManager.m:182
    frame #10: 0x001bdf3c xxxxxx`...
    frame #11: 0x001799c8 xxxxxx`...
    frame #12: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #13: 0x0052d8e8 libdispatch.dylib`_dispatch_after_timer_callback + 108
    frame #14: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #15: 0x0053756c libdispatch.dylib`_dispatch_source_latch_and_call + 2256
    frame #16: 0x00525b42 libdispatch.dylib`_dispatch_source_invoke + 738
    frame #17: 0x00528156 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 402
    frame #18: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #19: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #20: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #21: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #22: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #23: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #24: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #25: 0x20768872 libdyld.dylib`start + 2
+++ Incrementing Activity Count -incrementActivityCount
* thread #1: tid = 0x95bc4d, 0x0046e8b0 AFNetworking`-[AFNetworkActivityIndicatorManager incrementActivityCount](self=0x1764d4f0, _cmd="incrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:130, queue = 'com.apple.main-thread', stop reason = breakpoint 10.1
  * frame #0: 0x0046e8b0 AFNetworking`-[AFNetworkActivityIndicatorManager incrementActivityCount](self=0x1764d4f0, _cmd="incrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:130
    frame #1: 0x0046ec58 AFNetworking`-[AFNetworkActivityIndicatorManager networkRequestDidStart:](self=0x1764d4f0, _cmd="networkRequestDidStart:", notification=@"com.alamofire.networking.task.resume") + 142 at AFNetworkActivityIndicatorManager.m:158
    frame #2: 0x20b5f344 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #3: 0x20b5ed52 CoreFoundation`_CFXRegistrationPost + 398
    frame #4: 0x20b5eb28 CoreFoundation`___CFXNotificationPost_block_invoke + 40
    frame #5: 0x20bb5f62 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1334
    frame #6: 0x20abe0ea CoreFoundation`_CFXNotificationPost + 486
    frame #7: 0x21303b16 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    frame #8: 0x2130864a Foundation`-[NSNotificationCenter postNotificationName:object:] + 30
    frame #9: 0x0048e8f8 AFNetworking`__37-[AFURLSessionManager taskDidResume:]_block_invoke(.block_descriptor=0x175e6cf0) + 132 at AFURLSessionManager.m:488
    frame #10: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #11: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #12: 0x00528658 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1684
    frame #13: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #14: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #15: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #16: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #17: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #18: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #19: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #20: 0x20768872 libdyld.dylib`start + 2
+++ Incrementing Activity Count -incrementActivityCount
* thread #1: tid = 0x95bc4d, 0x0046e8b0 AFNetworking`-[AFNetworkActivityIndicatorManager incrementActivityCount](self=0x1764d4f0, _cmd="incrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:130, queue = 'com.apple.main-thread', stop reason = breakpoint 10.1
  * frame #0: 0x0046e8b0 AFNetworking`-[AFNetworkActivityIndicatorManager incrementActivityCount](self=0x1764d4f0, _cmd="incrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:130
    frame #1: 0x0046ec58 AFNetworking`-[AFNetworkActivityIndicatorManager networkRequestDidStart:](self=0x1764d4f0, _cmd="networkRequestDidStart:", notification=@"com.alamofire.networking.task.resume") + 142 at AFNetworkActivityIndicatorManager.m:158
    frame #2: 0x20b5f344 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #3: 0x20b5ed52 CoreFoundation`_CFXRegistrationPost + 398
    frame #4: 0x20b5eb28 CoreFoundation`___CFXNotificationPost_block_invoke + 40
    frame #5: 0x20bb5f62 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1334
    frame #6: 0x20abe0ea CoreFoundation`_CFXNotificationPost + 486
    frame #7: 0x21303b16 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    frame #8: 0x2130864a Foundation`-[NSNotificationCenter postNotificationName:object:] + 30
    frame #9: 0x0048e8f8 AFNetworking`__37-[AFURLSessionManager taskDidResume:]_block_invoke(.block_descriptor=0x18e9d370) + 132 at AFURLSessionManager.m:488
    frame #10: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #11: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #12: 0x00528658 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1684
    frame #13: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #14: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #15: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #16: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #17: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #18: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #19: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #20: 0x20768872 libdyld.dylib`start + 2
>>> -POST:parameters:constructingBodyWithBlock:success:failure:
* thread #1: tid = 0x95bc4d, 0x0046c5ba AFNetworking`__82-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:]_block_invoke.73(.block_descriptor=<unavailable>, response=0x189d27a0, responseObject=2 key/value pairs, error=0x00000000) + 120 at AFHTTPSessionManager.m:177, queue = 'com.apple.main-thread', stop reason = breakpoint 17.1
  * frame #0: 0x0046c5ba AFNetworking`__82-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:]_block_invoke.73(.block_descriptor=<unavailable>, response=0x189d27a0, responseObject=2 key/value pairs, error=0x00000000) + 120 at AFHTTPSessionManager.m:177
    frame #1: 0x0048c620 AFNetworking`__72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.71(.block_descriptor=<unavailable>) + 204 at AFURLSessionManager.m:202
    frame #2: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #3: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #4: 0x00528658 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1684
    frame #5: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #6: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #7: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #8: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #9: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #10: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #11: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #12: 0x20768872 libdyld.dylib`start + 2
--- Decrementing Activity Count -decrementActivityCount
* thread #1: tid = 0x95bc4d, 0x0046ea3a AFNetworking`-[AFNetworkActivityIndicatorManager decrementActivityCount](self=0x1764d4f0, _cmd="decrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:142, queue = 'com.apple.main-thread', stop reason = breakpoint 11.1
  * frame #0: 0x0046ea3a AFNetworking`-[AFNetworkActivityIndicatorManager decrementActivityCount](self=0x1764d4f0, _cmd="decrementActivityCount") + 42 at AFNetworkActivityIndicatorManager.m:142
    frame #1: 0x0046eeec AFNetworking`-[AFNetworkActivityIndicatorManager networkRequestDidFinish:](self=0x1764d4f0, _cmd="networkRequestDidFinish:", notification=@"com.alamofire.networking.task.complete") + 142 at AFNetworkActivityIndicatorManager.m:164
    frame #2: 0x20b5f344 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #3: 0x20b5ed52 CoreFoundation`_CFXRegistrationPost + 398
    frame #4: 0x20b5eb28 CoreFoundation`___CFXNotificationPost_block_invoke + 40
    frame #5: 0x20bb5f62 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1334
    frame #6: 0x20abe0ea CoreFoundation`_CFXNotificationPost + 486
    frame #7: 0x21303b16 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    frame #8: 0x0048c742 AFNetworking`__72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_3(.block_descriptor=0x18bb42e0) + 148 at AFURLSessionManager.m:206
    frame #9: 0x00523ba6 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #10: 0x00523b92 libdispatch.dylib`_dispatch_client_callout + 22
    frame #11: 0x00528658 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1684
    frame #12: 0x20b6f7d4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #13: 0x20b6dcce CoreFoundation`__CFRunLoopRun + 1590
    frame #14: 0x20abc288 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #15: 0x20abc07c CoreFoundation`CFRunLoopRunInMode + 108
    frame #16: 0x220d8af8 GraphicsServices`GSEventRunModal + 160
    frame #17: 0x251e12c4 UIKit`UIApplicationMain + 144
    frame #18: 0x00158a64 xxxxxx`main(argc=1, argv=0x00441b74) + 106 at main.m:16
    frame #19: 0x20768872 libdyld.dylib`start + 2

(lldb) breakpoint list
Current breakpoints:
1: names = {'objc_exception_throw', '__cxa_throw'}, locations = 4, resolved = 2, hit count = 0

  1.1: re-exported target = libc++abi.dylib`__cxa_throw, address = libc++abi.dylib[0x2008c584], unresolved, hit count = 0 
  1.2: where = libobjc.A.dylib`objc_exception_throw, address = libobjc.A.dylib[0x2009adf0], unresolved, hit count = 0 
  1.3: where = libobjc.A.dylib`objc_exception_throw, address = 0x2036add8, resolved, hit count = 0 
  1.4: where = libc++abi.dylib`__cxa_throw, address = 0x2035c584, resolved, hit count = 0 

8: file = 'xxxxxx/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m', line = 157, exact_match = 0, locations = 1 Options: disabled 

  8.1: where = AFNetworking`-[AFNetworkActivityIndicatorManager networkRequestDidStart:] + 28 at AFNetworkActivityIndicatorManager.m:157, address = 0x0046ebe6, unresolved, hit count = 8  Options: disabled 

9: file = 'xxxxxx/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m', line = 163, exact_match = 0, locations = 1 Options: disabled 

  9.1: where = AFNetworking`-[AFNetworkActivityIndicatorManager networkRequestDidFinish:] + 28 at AFNetworkActivityIndicatorManager.m:163, address = 0x0046ee7a, unresolved, hit count = 4  Options: disabled 

10: file = 'xxxxxx/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m', line = 130, exact_match = 0, locations = 1, resolved = 1, hit count = 10

  10.1: where = AFNetworking`-[AFNetworkActivityIndicatorManager incrementActivityCount] + 42 at AFNetworkActivityIndicatorManager.m:130, address = 0x0046e8b0, resolved, hit count = 10 

11: file = 'xxxxxx/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m', line = 142, exact_match = 0, locations = 1, resolved = 1, hit count = 5

  11.1: where = AFNetworking`-[AFNetworkActivityIndicatorManager decrementActivityCount] + 42 at AFNetworkActivityIndicatorManager.m:142, address = 0x0046ea3a, resolved, hit count = 5 

12: file = 'xxxxxx/Pods/AFNetworking/AFNetworking/AFURLSessionManager.m', line = 495, exact_match = 0, locations = 1, resolved = 1, hit count = 0

  12.1: where = AFNetworking`-[AFURLSessionManager taskDidSuspend:] + 50 at AFURLSessionManager.m:495, address = 0x0048e970, resolved, hit count = 0 

13: file = 'xxxxxx/Pods/AFNetworking/AFNetworking/AFURLSessionManager.m', line = 484, exact_match = 0, locations = 1, resolved = 1, hit count = 6

  13.1: where = AFNetworking`-[AFURLSessionManager taskDidResume:] + 50 at AFURLSessionManager.m:484, address = 0x0048e702, resolved, hit count = 6 

16: file = '/xxxxxx/Pods/AFNetworking/AFNetworking/AFURLRequestSerialization.m', line = 451, exact_match = 0, locations = 1, resolved = 1, hit count = 1

  16.1: where = AFNetworking`-[AFHTTPRequestSerializer multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:] + 2298 at AFURLRequestSerialization.m:451, address = 0x0047cf02, resolved, hit count = 1 

17: file = 'xxxxxx/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m', line = 177, exact_match = 0, locations = 1, resolved = 1, hit count = 1

  17.1: where = AFNetworking`__82-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:success:failure:]_block_invoke.73 + 120 at AFHTTPSessionManager.m:177, address = 0x0046c5ba, resolved, hit count = 1 

(lldb) 

Note: although I forgot to log the actual value of _activityCount in the LLDB console, I did verify the counter was being increased twice and decremented once for each multi-part post.

FWIW: Commenting out the notification subscription for 'resume' eliminates the second call to AFNetworkActivityIndicatorManager -incrementActivityCount

- (id)init {
    self = [super init];
    if (!self) {
        return nil;
    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidStart:) name:AFNetworkingOperationDidStartNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingOperationDidFinishNotification object:nil];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidStart:) name:AFNetworkingTaskDidResumeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingTaskDidSuspendNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingTaskDidCompleteNotification object:nil];
#endif

    return self;
}

Closing this issue due to age. If this is still occurring on v4, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings