LoginSignup
1
2

More than 1 year has passed since last update.

【Swift】WebViewに表示されない問題

Posted at

はじめに

WebViewを使っていて、表示できないサイトがありました。
原因を調べるとhttpsではなくhttpだからでした。
httpでも表示できるようにしたので記録しておきます。

WebViewはこちらのコードを使用しています。

コード

import SwiftUI

struct ContentView: View {
    private let url = URL(string: "http://www.chiseki.go.jp/")
    var body: some View {
        WebView(url: url)
            .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
    }
}

何も設定していないと真っ白の画面になってしまいます。

解決方法

① プロジェクトを選択します
② ターゲットを選択します
③ 「Info」を選択します
④ 1番下の「+」を選択します
スクリーンショット 2023-02-15 21.49.28.jpg

NSAppTransportSecurityを入力します
スクリーンショット 2023-02-15 21.52.54.jpg

⑥ 矢印をタップして下向きにします
⑦ 「+」をタップします
スクリーンショット 2023-02-15 21.54.16.jpg

NSAllowsArbitraryLoadsを入力します旧
スクリーンショット 2023-02-15 21.56.15.jpg

⑨ 「YES」に変更します
スクリーンショット 2023-02-15 21.57.26.jpg

設定終了!!

確認

実行してみます
表示されました!!
simulator_screenshot_AF75F18E-94F4-4D32-B305-7C76F29D3CE6.png

おわり

これは知らないと沼りそうな箇所ですね

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2