I'm kind of new in objective c, but I'm developing an app which has a UIWebView that loads some web content. All the web pages require client certificate for authentication and I'm struggling with it for dew days. Does anyone know the flow how to implement it in UIWebView?
Thanks!
To avoid any problem in the UIWebView, you have to make a reques to you website root, with the client certificate, before the request of the web view. You can use the UIWebViewDelegate method:
After this, the UIWebView will be able to load everything without any problem.
If you are new to Objective-C, I guess you are also new to the Foundation framework so here's a bit of help.
To solve this, I used ASIHTTPRequest as it was already embedded in our project. But you can use a NSURLConnection and do the logic in the NSURLConnectionDelegate method:
So, here's my code to provide a client certificate to an ASIHTTPRequest prior to a UIWebView request:
I'm sending the request synchronously to ensure its completion before letting the UIWebView starts its loading.
I use a method to retrieve the identity from the certificate, which is:
Here the same technique, but using the NSURLConnection instead of the ASIHTTPRequest
to use a certificate with a NSURLConnection, you have to implement the the NSURLConnectionDelegate method:
In this method, the NSURLConnection is telling you that it received a challenge. You will have to create a NSURLCredential to send back to the [challenge sender]
So you create your NSURLCredential:
And finally use it with
on [challenge sender]
You should have everything needed. Good luck.