ClickSend v3 REST API的官方Swift库
这是官方的ClickSend SDK。您可以在此处找到文档。
需求
安装
将包放在项目文件夹下,并在`import`中添加以下代码
"./clicksend-swift"
文档
关于我们的SDK和REST API的文档,您可以在这里找到。
入门(sms/send示例)
请遵循安装步骤,然后运行以下代码。
import Alamofire
if let authHeader = Request.authorizationHeader(user: "USERNAME", password: "PASSWORD") {
ClickSendClientAPI.customHeaders = [authHeader.key : authHeader.value]
}
let message1 = SmsMessage(
body: "Chocolate bar icing icing oat cake carrot cake jelly cotton MWEvciEPIr.",
to: "+0451111111",
source: "swift"
)
let message2 = SmsMessage(
body: "Chocolate bar icing icing oat cake carrot cake jelly cotton MWEvciEPIr.",
source: "swift",
listId: 1234
)
let smsCollection = SmsMessageCollection(messages: [message1, message2])
SMSAPI.smsSendPost(smsMessages: smsCollection) { (dataString, error) in
guard let dataString = dataString else {
print(error!)
return
}
if let data = dataString.data(using: String.Encoding.utf8) {
do {
if let dictonary = try (JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary) {
print(dictonary)
} else {
print("bad json")
}
} catch let error as NSError {
print(error)
}
}
}