I. master the operation method of Swift – urlsession access SMS verification code

Time:2021-10-19

It is very practical to use swift to access SMS verification code through urlsession. Share the process of accessing SMS verification code in project development, as shown below:
`import Foundation

var semaphore = DispatchSemaphore (value: 0)

let parameters = “appId=41KYR0EB&appKey=IIWCKKSR7NOQ&phone=1561894**&templateId=1043&variables=1234″
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: “https://vip.veesing.com/smsApi/verifyCode”)!,timeoutInterval: Double.infinity)
request.addValue(“application/x-www-form-urlencoded;charset=utf-8”, forHTTPHeaderField: “Content-Type”)

request.httpMethod = “POST”
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {

print(String(describing: error))
return

}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}

task.resume()
semaphore.wait()`

The above is the operation method of Swift – urlsession access SMS verification code. It’s not easy to be original. I hope you can give me a one button three connection.
Swift – urlsession.swift and documentation Download

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]