Hello,
Firstly, you can add next code to your Info.plist file to allow self signed certificate in iOS.(Before submitting app to the Appstore, please set"Allow Arbitrary Loads" to No.)
Note that using self-signed certificates is generally not recommended for production scenarios. It is better to use certificates signed by a trusted certificate authority (CA) to ensure a secure connection.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Or you can set specific domain in Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>[YOUR BASE URL HERE]</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</dict>
Then you can create a custom renderer for webview. Then you can create a WebViewDelegate
implement WKNavigationDelegate and INSUrlConnectionDataDelegate to allow ServerSecTrust
[assembly: ExportRenderer(typeof(WebView), typeof(MyCustomWebview))]
namespace XFCertificate.iOS
{
public class MyCustomWebview: ViewRenderer<WebView, WKWebView>
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var webView = new WKWebView(Frame, new WKWebViewConfiguration());
webView.NavigationDelegate = new WebViewDelegate();
SetNativeControl(webView);
}
if (e.NewElement != null)
{
Control.LoadRequest(new NSUrlRequest(new NSUrl(e.NewElement.Source.ToString())));
}
}
}
public class WebViewDelegate : WKNavigationDelegate, INSUrlConnectionDataDelegate
{
public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler)
{
completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, new NSUrlCredential(challenge.ProtectionSpace.ServerSecTrust));
return;
}
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.