The same code has no problem with iOS8, and iOS7 cannot get data (the errors such as Cocoa Error 3840 will be included). Tracking and finding that the requested head parameter setting is not useful. I changed the compatible code according to the reference at the bottom of the text:
Code private func getRequest(method: Method, _ URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil) -> NSMutableURLRequest { let request = NSMutableURLRequest(URL: NSURL(string: )!) = if parameters != nil { = (parameters!, options: nil, error: nil) } (API_UA, forHTTPHeaderField: "User-Agent") (HEADER_ACCEPT, forHTTPHeaderField: "Accept") ("application/json", forHTTPHeaderField: "Content-Type") return request }
Here, change API_UA and HEADER_ACCEPT to their own head parameters, use the code:
var request: Request! if DeviceUtils.isIOS7() { request = (getRequest(method, URLString, parameters: parameters)) } else { request = (method, URLString , parameters: parameters, encoding: ) } //....
Code description:
a) mHttpManager is, please don’t forget to set it up, it still works in iOS8.
refer to:
Setting Custom HTTP Headers in Alamofire in iOS 7 not working (refer to the post, also tried setting NSURLSessionConfiguration but had no effect)
The above is a compilation of the information on setting up the Head of the Alamofire library under iOS. I hope it can help students who develop IOS software.