I'm having a bit of a problem with AFNetworking in a share extension. In the didSelectPost
, I'm calling:
[[AuthClient sharedClient] POST: @"/v1/events"
parameters: params success: ^ (AFHTTPRequestOperation * operation, id responseObject) {
[self.extensionContext completeRequestReturningItems: nil completionHandler: nil];
}
failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {
NSLog(@"error: %@", error);
[self.extensionContext cancelRequestWithError: error];
}
];
[AuthClient sharedClient]
uses the singleton pattern to get an instance of AFHTTPSessionManager
with NSURLSessionConfiguration
set with a background identifier.
However, neither the success or failure callbacks are invoked and it just hangs indefinitely until the extension gets killed. Interestingly, the HTTP request finishes fine on the server side; the completion just never gets invoked.
I guess, the problem isn't with AFNetworking
but problem is with that singleton class. You have not specified your app's architecture, but I'm assuming that, you may calling multiple APIs in different view controllers using the same [AuthClient sharedClient]
singleton at the same time. Hence, you're actually receiving a success
call but not for the above call but some where else in your controller. I have faced the exact issue in my UITabbarController
based application where I was making API calls in viewDidLoad
of different view controllers and my tester was continuously changing all tabs. Thus, I tried to get response for first view controller (1st tab) and used to get response in second view controller (2nd tab), which was wrong!
1) Try to execute this request in Postman, for check the right way and parameters, if ok -> 2.
2) Try to use session configuration like this
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
// Initialize Session Manager
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:sessionConfiguration];
at this point we can assume that your singletone was initialised for another request with different configuration.
3) similar problem
4) about AFNetworking background
P.S. Try to use simple asynchronous on main thread, with spinner while waiting response
Some things I'd try:
Hopefully some of this can bring you closer to an idea of what's causing the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With