LoginSignup
0
1

More than 1 year has passed since last update.

【Swift】WebViewで "NSURLErrorDomain, code = -1022" のエラーが出てページが表示されない問題

Last updated at Posted at 2021-08-12

どういうことか

iOSアプリを開発している。
他所が作ったWebページと連携するためWebViewで表示しようと思ったら真っ白なページが表示され、Xcodeのコンソールに掲題のエラーが表示される。
Webインスペクタで確認するとどうやらリダイレクトする処理が書かれており、遷移する先がhttpでは?と疑ってみたもののhttpsになっている。

検証

対象のページがATS (App Transport Security) に対応しているか、ターミナルでコマンドを叩いて検証してみる。

$ nscurl --ats-diagnostics --verbose https://[URL]

Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made.

ダメだったらしい。
エラーが発生しました。Error Domain=NSURLErrorDomain Code=1200 "SSLエラーが発生したため、サーバーへの安全な接続ができません』と書いてある。

解決策

上記のコマンドに --verbose のオプションを付けたことで、いろんなパターンの結果と解決策がいくつか出てくる。
PASS がOKだったパターン、FAIL がダメだったパターン。

Disabling Perfect Forward Secrecy
ATS Dictionary:
{
    NSExceptionDomains =     {
        "対象のドメイン" =         {
            NSExceptionRequiresForwardSecrecy = false;
        };
    };
}
Result : PASS

このパターンを使う。

解消する

info.plistに追記する

  1. どこかで +ボタンを押して App Transport Security Settings を追加
  2. 1の中に Exception Domains を追加
  3. 2の中に対象のドメインを追加。Typeを Dictionary に変更
  4. 3の中に NSExceptionRequiresForwardSecrecy を追加。Typeを Boolean にし、Valueを 0(falseを表す)に設定

これで表示されるようになった。

おわりに

そもそもWebページの方を見直すべきかもしれないし、この設定が企業のセキュリティ要件などに引っかかるかもしれないので、そのあたりはきちんとすり合わせを行う。

0
1
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
0
1