1.图文网络加载:
Kingfisher:https://github.com/onevcat/Kingfisher
imgview.kf.setImage(with: uri,placeholder: UIImage(named: imgdefault))
2.消息总线
SwiftEventBus (https://github.com/onevcat/Kingfisher)
override func viewDidDisappear(_ animated: Bool) {
SwiftEventBus.unregister(self)
}
SwiftEventBus.onMainThread(self, name: "xxxx", handler: { params in
let productId = params!.object as! Int
})
SwiftEventBus.post("xxxx", sender: Int)
3.Http请求
SwiftHttp
1.GET
HTTP.GET(url,parameters: params,headers: headers)
2.POST
HTTP.POST(url,parameters: params)
3.发送文件,需要构造Upload对象
headers["Content-Type"] = "multipart/form-data";
postParas["pic"] = Upload.init(data: fileList[index], fileName:"pic.jpeg" , mimeType: "application/octet-stream")
4.用例:
fileprivate func doPost(url:String,params:[String:Any],headers:[String:String],completion:@escaping (_:Bool,_:String?,_:[String:Any]?)->Void,userParam:[String:Any]?){
print("doPost:\(url):\(params)")
HTTP.POST(url,parameters: params){ response in
if let err = response.error{
print("error:\(err.localizedDescription)")
if Thread.isMainThread{
completion(false,err.localizedDescription,userParam)
}else{
DispatchQueue.main.async {
completion(false,err.localizedDescription,userParam)
}
}
}else{
print("data:\(String(describing: response.text))")
if Thread.isMainThread{
completion(true,response.text,userParam)
}else{
DispatchQueue.main.async {
completion(true,response.text,userParam)
}
}
}
}
}
4.ping请求
SwiftyPing:https://github.com/samiyr/SwiftyPing 这个在网上有很多,但是只有一个功能正常,且不存在内存泄漏
5.解析Json
SwiftyJSON
6.内购
SwiftyStoreKit
使用很简单但是,请注意在确认订单完(verifyPurchase)之前不要调用:finishTransaction,否则在验证订单的时候会提示该订单不存在。
fetchReceipt或者verifyPurchase之后,该笔订单会将不在需要finishTransaction。
|