開発したアプリなど一覧

Xamarin iOS で https でない Web ページを WebView で開く

アフィリエイトリンクを含む場合があります

Xamarin を使用したアプリで自分のページを WebView を開こうとしたところ、以下のようなメッセージが出力され、Web ページを開く事ができなかった。

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

どうやら iOS では ATS(App Transport Security) という仕組みにより http での通信はデフォルトではブロックされる仕様のようだ。

http://developer.hatenastaff.com/entry/2016/06/16/165924

本来であればサーバを https 対応にするほうが良いのだろうけど、今すぐ https 対応にできないので、アプリ側で http でも通信できるように設定をしてみた。

幸い Xamarin のページに ATS の設定方法が記載されていたので、それを見ながら Info.plist を編集したところ、https でないページもアクセスできるようになった。

https://developer.xamarin.com/guides/ios/platform_features/introduction_to_ios9/ats/

Xamarin の iOS 向けプロジェクトから Info.plist を開き、以下のような感じに設定する。

NSAppTransportSecurity - Dictionary NSExceptionDomains - Dictionary (ドメイン名) - Dictionary NSExceptionMinimumTLSVersion - string - TLSv1.0 NSExceptionRequiresForwardSecrecy - Boolean - No NSExceptionAllowsInsecureHTTPLoads - Boolean - Yes NSIncludesSubdomains - Boolean - Yes

こうする事で指定したドメインだけを WebView で表示する事ができるようになる。

また、NSAppTransportSecurity 以下に NSAllowArbitraryLoadsInWebContent を追加し YES にするとドメイン関係なく WebView で https でないページも開く事ができるようだ。

Sponsored Link

コメント

タイトルとURLをコピーしました