AFN數(shù)據(jù)請(qǐng)求(swift終極版)
//頭文件
import AFNetworking
//AFN數(shù)據(jù)請(qǐng)求(swift終極版)
let manager = AFHTTPSessionManager()
manager.responseSerializer.acceptableContentTypes?.insert("application/json")
let path = "https://test.kemeiapp.com/outer/v1/video/getVideoType.do"
let dict = ["sorted":1]
manager.post(path, parameters: dict, progress:nil, success: {(URLSessionDataTask,responseObject) in
//轉(zhuǎn)換類型
let responseObject = responseObject as AnyObject
print("得到數(shù)據(jù):\(responseObject)")
//回到主線程
if responseObject["code"] as? String == "00" {
//主線程
DispatchQueue.main.async {
print("走00成功");
}
}
}) { (URLSessionDataTask,error) in
print("數(shù)據(jù)請(qǐng)求失敗\(error.localizedDescription)");
//沒(méi)網(wǎng)等各種錯(cuò)誤提示(把句號(hào)替換成空白)
// MBProgressHUD .showNoNetwork(error.localizedDescription.replacingOccurrences(of: "林说。", with: ""))
}
}