I know this is a pretty old post, but it was a pretty interesting question, so I had to go for it. Therefore, if you still need it (most likely not), or if someone finds this post, here is a ported version of your own UIWebView with support for self-signing. It can be used as a regular UIWebView, except that as an additional parameter a host name is required, which should be the host name on the page where certificate verification should be disabled.
public class InsecureWebView : UIWebView, INSUrlConnectionDataDelegate, IUIWebViewDelegate { public InsecureWebView(string baseUrl) : base() { Setup (baseUrl); } public InsecureWebView(CoreGraphics.CGRect rect, string baseUrl) : base(rect) { Setup (baseUrl); } public InsecureWebView(NSCoder coder, string baseUrl) : base(coder) { Setup (baseUrl); } public InsecureWebView(NSObjectFlag t, string baseUrl) : base(t) { Setup (baseUrl); } public InsecureWebView(IntPtr handler, string baseUrl) : base(handler) { Setup (baseUrl); } string baseUrl = null; bool authenticated; NSUrlRequest failedRequest; private void Setup(string baseUrl) { this.Delegate = this; this.baseUrl = baseUrl; } [Foundation.Export ("webView:shouldStartLoadWithRequest:navigationType:")] public bool ShouldStartLoad (UIKit.UIWebView webView, Foundation.NSUrlRequest request, UIKit.UIWebViewNavigationType navigationType) { var result = authenticated; if (!authenticated) { failedRequest = request; NSUrlConnection.FromRequest (request, this); } return result; } [Foundation.Export ("connection:willSendRequestForAuthenticationChallenge:")] public void WillSendRequestForAuthenticationChallenge (NSUrlConnection connection, NSUrlAuthenticationChallenge challenge) { if (challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodServerTrust) { var baseUrl = new NSUrl (this.baseUrl); if (challenge.ProtectionSpace.Host == baseUrl.Host) { challenge.Sender.UseCredential (NSUrlCredential.FromTrust (challenge.ProtectionSpace.ServerSecTrust), challenge); } } challenge.Sender.ContinueWithoutCredential (challenge); } [Foundation.Export ("connection:didReceiveResponse:")] public void DidReceivedResponse(NSUrlConnection connection, NSUrlResponse response) { authenticated = true; connection.Cancel (); LoadRequest (failedRequest); } }
source share