一 初始设置
//appdelegate中 创建缓存
NetworkReachabilityManager.init()?.startListening()
let urlCache = URLCache.init(memoryCapacity: 4*1024*1024, diskCapacity: 20*1024*1024, diskPath: nil)
URLCache.shared = urlCache
二 网络请求
let manager: SessionManager = {
let configuration = URLSessionConfiguration.default
let reachability = NetworkReachabilityManager()
if (reachability?.isReachable)! {
configuration.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData
}else
{
configuration.requestCachePolicy = .returnCacheDataElseLoad
}
return Alamofire.SessionManager(configuration: configuration)
}()
manager.request("http://192.168.1.133:8080/b------/squareList",method : .post ,parameters :["begin": page,"token": currentUser.token]).responseJSON { (response) in
let dataResponse = JSON(response.data!)
let data = dataResponse["data"]
completion(true, data.arrayValue.count < perPage, data.arrayValue.map({ Wish(json: $0) }))
manager.session.invalidateAndCancel()
}
先简单记录 后续会细化:)
网友评论