Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Last active January 30, 2020 11:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelbeek/6f0de1752c3d30427705 to your computer and use it in GitHub Desktop.
Save samuelbeek/6f0de1752c3d30427705 to your computer and use it in GitHub Desktop.
Send Text with MessageBird
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