close

在撰寫Swift時,我們很常需要和Web Service API來取得資料及操作,所以在取得Web Service的json格式資料時,發現有以下的錯誤:

Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x61800005f350 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://3a0ebbd1.ngrok.io/rest/angular/, NSErrorFailingURLKey=http://3a0ebbd1.ngrok.io/rest/angular/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

解決方法:

開啟Info.plist檔案後,在Information Property List下新增一個Dictionary名稱為App Transport Security Settings,接著在此項目下新增一個屬性Allow Arbitrary Loads值為YES。

接著只要儲存並重新Build程式後就可以發現不會產生上述的Error了。

arrow
arrow
    文章標籤
    ios swift xcode configuration
    全站熱搜

    JerryCh 發表在 痞客邦 留言(0) 人氣()