IOS 常用第三方库

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
           //object发送过来的参数类型
           let productId = params!.object as! Int
 })

//发送消息,sender为任意类型,这里以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。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值