コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】iOS の WebView で自己署名証明書を使用しているサーバの Web ページを表示したい場合

概要

Unity でビルドした iOS アプリで「unity-webview」を使用して
自己署名証明書を使用しているサーバの Web ページを表示したい場合、

上記のサイト様で記載されている以下のコードを
「WebView.mm」に記述することで Web ページを表示できるようになる

WKWebView* webView = [[WKWebView alloc] initWithFrame:bounds configuration:webConfig];
webView.navigationDelegate = self;

- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
    NSURLCredential* credential = [[NSURLCredential alloc] initWithTrust:[challenge protectionSpace].serverTrust];
    completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}