IOS 常用第三方库

这篇博客介绍了iOS开发中常用的几个库和功能。Kingfisher用于图片加载,SwiftEventBus实现消息总线通信,SwiftHttp处理网络请求,包括GET、POST及文件上传。同时,文章提到了SwiftyPing进行ping测试,SwiftyJSON解析JSON数据,以及SwiftyStoreKit进行内购处理,强调了在内购过程中验证订单的重要性。
部署运行你感兴趣的模型镜像

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。

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值