AFNetworking: Handle error globally and repeat request

前端 未结 6 1654
温柔的废话
温柔的废话 2020-12-07 11:07

I have a use case that should be rather common but I can\'t find an easy way to handle it with AFNetworking:

Whenever the server returns a specific status code for <

6条回答
  •  悲哀的现实
    2020-12-07 12:12

    Took a similar approach, but I couldn't get the status code object with phix23's answer so I needed a different plan of action. AFNetworking 2.0 changed a couple of things.

    -(void)networkRequestDidFinish: (NSNotification *) notification
    {
        NSError *error = [notification.userInfo objectForKey:AFNetworkingTaskDidCompleteErrorKey];
        NSHTTPURLResponse *httpResponse = error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey];
        if (httpResponse.statusCode == 401){
            NSLog(@"Error was 401");
        }
    }
    

提交回复
热议问题