Q1.出現
"resource load since it is insecure" 或者
"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection"(該提示不一定有,主要是第一段提示)
這兩段錯誤提示
解決方式:
①選中info.plist
②選中Information Property List后面的加號➕
③彈框中選擇App Transport Security Settings
④點擊App Transport Security Settings前的箭頭,再點擊加號➕
⑤彈框僅有三個選項,選擇Allow Arbitrary Loads
⑥將Allow Arbitrary Loads后的NO改成YES即可
Q2.出現
"Request failed: unacceptable content-type: text/html"錯誤提示
是由於JSon序列化有不支持的格式,即text/html
解決方式:
可通過閉包的形式往單例中添加格式支持
1 static let shareInstance: NetworkTools = { 2 let tools = NetworkTools() 3 tools.responseSerializer.acceptableContentTypes?.insert("text/html") 4 return tools 5 }()