Search code examples
iosibm-mobilefirst

iOS native failed connect to MFP server: requires the use of a secure connection


I'm trying to follow MobileFirst virtual PoT using CLI 7.1 and getting following error in Xcode console:

    2015-10-12 18:35:06.649 IBMBankNativeApp[45125:3922307] ViewController - viewDidLoad
    2015-10-12 18:35:06.650 IBMBankNativeApp[45125:3922307] ViewController - connectToServer - Initializing ...
   2015-10-12 18:35:06.651 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_CONFIG] -[WLConfig init] in WLConfig.m:68 :: {
"application id" = IBMBankNativeiOSApi;
"application version" = "1.0";
environment = iOSnative;
host = localhost;
platformVersion = "6.3.0.00.20141127-1357";
port = 10080;
protocol = http;
wlServerContext = "/MyMFPProject/";
wlUid = "wY/mbnwKTDDYQUvuQCdSgg==";
}
   2015-10-12 18:35:06.664 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] +[WLAFHTTPClientWrapper requestWithURL:] in WLAFHTTPClientWrapper.m:37 :: Request url is http://localhost:10080/MyMFPProject/apps/services/api/IBMBankNativeiOSApi/iOSnative/init
   2015-10-12 18:35:06.666 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_REQUEST] -[WLRequest sendRequest:path:withOptions:] in WLRequest.m:119 :: Request timeout is 60.000000
   2015-10-12 18:35:06.666 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_REQUEST] -[WLRequest sendRequest:path:withOptions:] in WLRequest.m:195 :: Sending request (http://localhost:10080/MyMFPProject/apps/services/api/IBMBankNativeiOSApi/iOSnative/init) with headers: 
{
"Accept-Language" = "en-US";
"User-Agent" = "IBMBankNativeApp/1.0 (iPhone; iOS 9.0; Scale/2.00)/WLNativeAPI/6.3.0.00.20141127-1357";
"X-Requested-With" = XMLHttpRequest;
"x-wl-app-version" = "1.0";
"x-wl-clientlog-appname" = IBMBankNativeiOSApi;
"x-wl-clientlog-appversion" = "1.0";
"x-wl-clientlog-deviceId" = "29C6B767-6E3B-430C-B5F6-5B2280290539";
"x-wl-clientlog-env" = iOSnative;
"x-wl-clientlog-model" = "x86_64";
"x-wl-clientlog-osversion" = "9.0";
"x-wl-platform-version" = "6.3.0.00.20141127-1357";
 }
   Post Data: action=test&isAjaxRequest=true
  2015-10-12 18:35:06.694 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper start] in  WLAFHTTPClientWrapper.m:182 :: Starting the request with URL http://localhost:10080/MyMFPProject/apps/services/api/IBMBankNativeiOSApi/iOSnative/init
  2015-10-12 18:35:06.751 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_REQUEST] -[WLRequest sendRequest:path:withOptions:] in WLRequest.m:200 :: waiting for response... (Thread=<NSThread: 0x7c269a60>{number = 1, name = main})
  2015-10-12 18:35:06.758 IBMBankNativeApp[45125:3922396] 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.
  2015-10-12 18:35:06.774 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:209 :: Request Failed
   2015-10-12 18:35:06.774 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:210 :: Response Status Code : 0
   2015-10-12 18:35:06.775 IBMBankNativeApp[45125:3922307] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFailed:error:] in WLAFHTTPClientWrapper.m:211 :: Response Error : The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

Should I somehow disable security for test environment?


Solution

  • Yes. Starting iOS 9 a secure connection is required.
    Follow the instructions in this blog post to learn more: https://developer.ibm.com/mobilefirstplatform/2015/09/09/ats-and-bitcode-in-ios9/

    For development-time easiest is to disable ATS, but remember to configure your application and server correctly as you move to production.

    Edit the info.plist file of your Xcode project. Add the following:

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>localhost</key>
        <dict>
          <!--Include to allow HTTP requests-->
          <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
      </dict>
    </dict>
    

    BTW, you say you use 7.1, but your application clearly shows you're using MFPF 6.3.