5
5

More than 5 years have passed since last update.

Ionic on iOS9.0 にて SSL error となる時の対処法

Posted at

問題

私の開発するアプリがiOS8.xでは動いていたが,iOS9.0からApp Transport Securityが変更されたため通信が制限されています。
そのためAn SSL error has occurred and a secure connection to the server cannot be made.とemulator,実機にてエラーが発生し通信ができなくなっています。

やること

今回,このAn SSL error has occurred and a secure connection to the server cannot be made.エラーを回避するためにInfo.plistをxCodeにて直接編集する方法がありますが、buildするたびに記述しなければいけないため自動化します.

前提条件

一応,私の環境を記しておきます.

$ ionic info
Cordova CLI: 5.3.3
Gulp version:  CLI version 3.9.0
Gulp local:   Local version 3.9.0
Ionic Version: 1.1.0
Ionic CLI Version: 1.7.7
Ionic App Lib Version: 0.6.3
ios-deploy version: 1.8.2 
ios-sim version: 5.0.3 
OS: Mac OS X El Capitan
Node Version: v0.12.2
Xcode version: Xcode 7.1 Build version 7B91b 

手法

  • config.xmlを編集します.
  • hooksを編集します.
  • Info.plistに適応されているか確認します.

config.xmlの編集

config.xmlを編集します.
Ionicで生成された場合,config.xmlはルートディレクトリにあります.これを編集します.

<platform name="ios">
    <config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
        <dict>
            <key>NSExceptionDomains</key>
            <dict>
                <key>yourserver.com</key>
                <dict>
                    <!--Include to allow subdomains-->
                    <key>NSIncludesSubdomains</key><true/>
                    <!--Include to allow HTTP requests-->
                    <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/>
                    <!--Include to specify minimum TLS version-->
                </dict>
            </dict>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </config-file>
</platform>

参考資料

hocksの編集

config.xmlを編集しただけですと,Info.plistは反映されません.
hooks/after_prepare/010_add_platform_class.jsを編集します.
これをコピペして使います.

$ npm install lodash elementtree plist
$ ionic run && ionic prepare

を行います.

Info.plistが適応されているかの確認

  • platforms/ios/${project_name}.xcodeprojをxCodeにて開きます.
  • Recources/${project_name}-Info.plistを開きます.
  • NSAppTransportSecurityが追記されているか確認します.

以上

5
5
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
5
5