Search code examples
iossslafnetworkingafnetworking-3

UIWebView+AFNetworking issue


I use this code:

webView.loadRequest(request!, progress: nil, success: { (responce, html) in
            print("\n\n\nsuccess responce = ", html)
            return html
        }, failure: { (error) in
            print("\n\n\nerror = ", error)
        })

But my server has invalid SSL sertificate. So I need to set a security policy. Before I was doing it like that:

[AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES;

But in AFNetworking 3 there is no AFHTTPRequestOperationManager class anymore. How can I set security policy for all requests in AFNetworking 3?


Solution

  • AFNetworking 3 equivalent of AFHTTPRequestOperationManager is AFHTTPSessionManager.

    So you should use this, on the webView itself:

    webView.sessionManager.securityPolicy.allowInvalidCertificates = YES;
    

    Of course the other solution is to fix the invalid certificate on the server.