1

Creating a Xamarin forms app that requires access to self signed websites.
The only way to accomplish this that I know of is to create custom web view renderers for each platform.
On Android, this can be accomplished by overriding OnReceivedSslError in the WebViewClient.

The question is how can we achieve this on iOS?

I have tried overriding NSUrlRequest as such:

public class MyUrlRequest : NSUrlRequest
{
    public MyUrlRequest(NSUrl url) : base(url)
    {
    }

    public MyUrlRequest(IntPtr p) : base(p)
    {
    }

    [Export("allowsAnyHTTPSCertificateForHost:")]
    public static bool Allow(string host)
    {
        return true;
    }

}

And calling the custom request using LoadRequest, but still does not seem to work.

boraseoksoon
  • 2,164
  • 1
  • 20
  • 25
a6547484
  • 81
  • 1
  • 7
  • Possible duplicate of [UIWebView to view self signed websites (No private api, not NSURLConnection) - is it possible?](http://stackoverflow.com/questions/11573164/uiwebview-to-view-self-signed-websites-no-private-api-not-nsurlconnection-i) – Cheesebaron Oct 11 '16 at 06:35

1 Answers1

0

To allow self signed certificate in iOS you can add next code to your Info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

or you can specify each domain:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>[ENTER YOUR BASE URL HERE]</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

See this post for more information.

Dima
  • 94
  • 2
  • 10