Last active
January 30, 2020 11:58
-
-
Save samuelbeek/6f0de1752c3d30427705 to your computer and use it in GitHub Desktop.
Send Text with MessageBird
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire // installation instructions for Alamofire can be found here: https://github.com/Alamofire/Alamofire | |
// Sends text message to phone number | |
func sendText(phoneNumber: String, message: String) { | |
let apiKey = "AccessKey YOUR_ACCES_KEY" | |
let originator = "YOUR_NAME" | |
// create a new manager instance (so you don't overwrite any other API's authorization) | |
var manager = Manager.sharedInstance | |
// set authorization | |
manager.session.configuration.HTTPAdditionalHeaders = ["Authorization": apiKey] | |
// perform request | |
manager.request(.POST, "https://rest.messagebird.com/messages", parameters: ["originator": originator, "recipients" : phoneNumber, "body": message], encoding: .JSON).responseJSON { (request, response, data, error) in | |
log("request \(request)") | |
log("response \(response)") | |
log("error: \(error)") | |
log("data: \(data)") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment