IOS之AFNetworking,SDWebImage,Kingfisher,Alamofire,FMDB框架的使用
IOS之AFNetworking,SDWebImage,Kingfisher,Alamofire,FMDB框架的使用
最近在B站上發(fā)表視頻,所有以cocoaPods 集成的框架都已經發(fā)表在B站,每一個視頻3~8分鐘不等。
cocoaPods的安裝不是那么容易,而且我是M1芯片的電腦。多次嘗試即可。
還有Kingfisher安裝并不是那么友好,Bug比較多,直接運行項目即可,不要亂點擊頭文件。
Xcode13.0 Bug較多,集成IOS15模擬機,即iPhone13的適配。但是包含框架的頭文件卻無法自動提示頭文件,很是費勁,需要自己手動敲出來,后期應該會修復這個bug。pod 在搜索到相應的框架之后,按 ctrl + Z鍵,可以終止終端的繼續(xù)搜索,這個要知道。shift + delete 可以慢慢刪一行代碼。AFNetworking,SDWebImage,FMDB是OC項目的使用的,Kingfisher,Alamofire是swift項目使用的,雖然可以混用,不建議混用。什么樣的項目使用什么樣的框架。
b站所有演示視頻地址在這https://www.bilibili.com/video/BV1f44y1b7zZ/,包含cocoaPods的安裝,我選擇的都是最新版本的框架,從github下載下來的。
由于Soundflower不支持M1芯片的電腦,導致我想內置聲音錄制下來并沒有成功,索性用外界麥克風解決問題,音質有點嘈雜。主要代碼貼出來。
1.AFNetworking
info.plist 加入ATS,
<key>NSAppTransportSecurity</key> <dict><key>NSAllowsArbitraryLoads</key><true/> </dict> // // ViewController.m // test // // Created by lujun on 2021/9/24. //#import "ViewController.h" #import <AFNetworking/AFNetworking.h> @implementation ViewController - (IBAction)getClick:(UIButton *)sender {NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];AFURLSessionManager *manage = [[AFURLSessionManager alloc] initWithSessionConfiguration:config];NSString *urlStr = @"http://httpbin.org/get";NSURL *url =[NSURL URLWithString:urlStr];NSURLRequest * request = [NSURLRequest requestWithURL:url];NSURLSessionDataTask *dataTask = [manage dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {if(error){NSLog(@" Error -- %@",error);}else{NSLog(@"%@ --- %@",response,responseObject);}}];[dataTask resume]; } @end2.SDWebInage的使用
// // ViewController.m // test2 // // Created by lujun on 2021/9/24. //#import "ViewController.h" #import "UIImageView+WebCache.h" @interface ViewController () @property(nonatomic,weak)UIImageView *iv; @end @implementation ViewController - (IBAction)click:(UIButton *)sender {UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(50, 200, 280, 290)];self.iv = iv;NSURL *url = [NSURL URLWithString:@"https://pics4.baidu.com/feed/6a63f6246b600c33cf333a6f1df47806d8f9a114.jpeg?token=dee9e2939f93b770534d4283fa9c2209"];[self.iv sd_setImageWithURL:url];[self.view addSubview:self.iv]; } - (void)viewDidLoad {[super viewDidLoad]; } @end3.FMDB框架
// // ViewController.m // IOSFMDBDemo // // Created by lujun on 2021/9/24. //#import "ViewController.h" #import <FMDatabase.h> @implementation ViewController - (void)viewDidLoad {[super viewDidLoad];NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];NSString *filePath = [doc stringByAppendingPathComponent:@"stuDemoTest.db"];FMDatabase *base = [FMDatabase databaseWithPath:filePath];NSLog(@"%@",NSHomeDirectory());if(![base open]){NSLog(@"打開失敗");return;}NSString *sqlStr = @"create table if not exists t_student(id integer primary key autoincrement,name text not null,age integer not null)";BOOL result = [base executeUpdate:sqlStr];if(result){NSLog(@"創(chuàng)建成功");}else{NSLog(@"創(chuàng)建失敗");} } @end4. Kingfisher 加載圖片網絡框架
// // ViewController.swift // kingfisherDemo // // Created by lujun on 2021/9/24. // import UIKit import Kingfisher class ViewController: UIViewController {@IBOutlet weak var imgView1: UIImageView!@IBAction func click(_ sender: Any) {let url1 = URL(string: "https://pics2.baidu.com/feed/9f510fb30f2442a7b31e01335a038742d01302d9.jpeg?token=9117fa84480937122f8e1e8264edd8c3")imgView1.kf.setImage(with: url1, placeholder: nil, options: nil, completionHandler: nil)}override func viewDidLoad() {super.viewDidLoad()} }5.Alamofire 網絡框架
// // ViewController.swift // IOSAlamofireDemo // // Created by lujun on 2021/9/24. // import UIKit import Alamofire class ViewController: UIViewController {override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {AF.request("http://httpbin.org/get").responseJSON{ (res) indebugPrint(res)}} }總結
以上是生活随笔為你收集整理的IOS之AFNetworking,SDWebImage,Kingfisher,Alamofire,FMDB框架的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马上有钱:揭密25种成为有钱人的方法(图
- 下一篇: 面试开发人员的有效方法