当前位置:网站首页>Packaging and use of alamofire framework
Packaging and use of alamofire framework
2022-07-23 16:09:00 【Hanyang Li】
1. Alamofire github Address : Alamofire
2. The terminal switches to the project folder , Execution instruction pod init , In the project folder , open Podfile file , Write stock in name
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target ' test -01-Alamofire' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for test -01-Alamofire
pod 'Alamofire'
end3. Back to the terminal , Input instruction pod search Alamofire -> pod help -> pod install --no-repo-update, Download finished Library
4. Test request method
/// Network request
/// - Parameters:
/// - method: GET / POST
/// - URLString: URLString
/// - parameters: Parameter Dictionary
/// - finished: Complete callback
private func request(method: HTTPMethod, URLString: String, parameters: [String: Any]?, finished: @escaping requestCallBack){
AF.request(URLString, method: method, parameters: parameters).responseJSON{ response in
switch response.result{
case let .success(data):
finished(data,nil)
break
case let .failure(error):
finished(nil,error)
break
}
}
}5. Test the method of uploading files
/// Upload files
private func upload(URLString: String, data: Data, name: String, parameters: [String: Any]?, finished: @escaping requestCallBack){
var parameter = parameters
// If you add token Failure , Go straight back to
if !appendToken(parameters: ¶meter){
// token Invalid
finished(nil,NSError(domain: "cn.cast.error", code: -1001, userInfo: ["message":"token It's empty "]))
return
}
/**
1. data To upload the binary of the file
2. name Is the field name defined by the server - The background interface document will prompt
3. fileName Is the file name saved in the server , however : Now you can usually write casually , The background will do some processing
- According to the uploaded file , Generate thumbnail , Medium map , High definition pictures
- Save in different paths , And automatically generate the file name
- fileName yes HTTP Properties defined by the Protocol
4. mimeType / contentType: The client notifies the server , Exact type of binary data
- Large type / Subtype
* image/gif image/jpg image/png
* text/plain text/html
* application/json
- Inaccurate type of server
* application/octet-stream
*/
//TODO
// post(URLString, parameters: parameter, headers: nil, constructingBodyWith: { formData in
// formData.appendPart(withFileData: data, name: name, fileName: "test", mimeType: "application/octet-stream")
// }, progress: nil) { _, result in
// finished(result,nil)
// } failure: { _, error in
// print(error)
// finished(nil,error)
// }
//2> Upload files
AF.upload(multipartFormData: { multipartFormData in
// Splice the binary data of the uploaded file
multipartFormData.append(data, withName: name, fileName: "test", mimeType: "application/octet-stream")
// Traverse the parameter dictionary , Generate corresponding parameter data
if let parameter = parameter {
for (k, v) in parameter {
let str = v as! String
let strData = str.data(using: .utf8)!
// data yes v Binary data of name yes K
multipartFormData.append(strData, withName: k)
}
}
}, to: URLString)
.responseJSON { response in
print(response.result)
switch response.result{
case let .success(data):
// Complete callback
finished(data,nil)
break
case let .failure(error):
// When developing network applications , Don't prompt the user for errors , But errors must be output
print(error)
finished(nil,error)
break
}
}
}边栏推荐
- ECS remote monitoring
- [in simple terms] from self information to entropy, from relative entropy to cross entropy, nn Crossentropyloss, cross entropy loss function and softmax, multi label classification
- "1+1 > 10": potential combination of no code / low code and RPA Technology
- Reproduce various counter attack methods
- Backup content hahaha
- Ultra detailed MP4 format analysis
- Gear monthly update June
- Chapter 4 event handling of quick mastering QML
- [untitled]
- 3D math - vector
猜你喜欢

【论文学习】《Source Mixing and Separation Robust Audio Steganography》

One minute rule for sequential disk access

再获殊荣 | OpenSCA获选中国软博会“全球十大开源软件产品”

太拼了!腾讯T4大佬凌晨4点还在熬夜,竟是在整理这分布式事务笔记
![[attack and defense world web] difficulty Samsung 9 points introductory question (Part 2): shrink, lottery](/img/05/06dd9f071fe18e4a50d767ec51e557.png)
[attack and defense world web] difficulty Samsung 9 points introductory question (Part 2): shrink, lottery

SSB signal modulation and demodulation based on MATLAB (with source code)
10": potential combination of no code / low code and RPA Technology"/>"1+1 > 10": potential combination of no code / low code and RPA Technology

Backup content hahaha

“1+1>10”:无代码/低代码与RPA技术的潜在结合

Design idea of initializing page input parameters
随机推荐
Pydensecrf installation
【论文学习】《Source Mixing and Separation Robust Audio Steganography》
《快速掌握QML》第四章 事件处理
Axure advanced
超详细MP4格式分析
FMDB的封装与使用
Software testing weekly (No. 81): what can resist negativity is not positivity, but concentration; What can resist anxiety is not comfort, but concrete.
Gear monthly update June
对专利的学习
Day14 function module
Reproduce various counter attack methods
Exclusive interview | open source Summer Star Niu Xuewei
《快速掌握QML》第五章 组件
Find the minimum value and location in multiple numbers (with repetition)
TranslucentTB 推荐
Expression du suffixe (une question par jour pendant les vacances d'été 4)
MySQL 灵魂 16 问,你能撑到第几问?
Chapter 4 event handling of quick mastering QML
ten thousand and one hundred
Php:filter pseudo protocol [bsidescf 2020]had a bad day