2016-01-28 77 views
0

现在我正在使用AFNetworking 2.0,我想将它迁移到AFNetworking 3.0。我已经将文件添加到项目中,它显示了很多错误。我检查了migration guide。我的疑问是如何将NSURLCredential设置为AFNetworking 3.0.4中的登录请求url。我现在用的,AFNetworking 3.0迁移

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 
if ([url rangeOfString:NSLoginUrl].location != NSNotFound) 
    { 
     NSURLCredential *credential = [NSURLCredential credentialWithUser:@"userName" password:@"password" persistence:NSURLCredentialPersistenceNone]; 
     [operation setCredential:credential]; 
    } 

AFNetworking 3不支持AFHTTPRequestOperationAFHTTPRequestOperationManager。请帮帮我。

回答

0

必须更换AFHTTPRequestOperation到AFHTTPSessionManager

然后AFNetworking 3.0暴露所有来自NSURLSession认证回调,您可以设置将通过AFURLRequestSerialization喜欢的标题。