In AFNetworking 3.0 some things was changed. Basicaly, there is no more operations, instead session data tasks
. How can I get status code from NSURLSessionDataTask
?
This is my block:
GET("users/check_email", parameters: parameters, progress: nil, success: { sessionDataTask, response in
// here I need status code of response
}) { sessionDataTask, error in
completionBlock(nil, NSError(sessionDataTask: sessionDataTask))
}
The NSURLSessionDataTask
has a response
property that can be cast to a NSHTTPURLResponse
to get the status code:
Swift Example:
if let urlResponse = sessionDataTask.response as? NSHTTPURLResponse {
let status = urlResponse.statusCode
}
Objective-C Example:
NSInteger statusCode = 0;
if ([sessionDataTask.response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)sessionDataTask.response;
statusCode = httpResponse.statusCode;
}
NSURLSessionDataTask
has response
property, which will be populated with an object of NSHTTPURLResponse
class, which has statusCode
property.
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