title: Twilio Send SMS in swift
body: <p>I'm trying to make an app that when you press a button it sends a text message to a preset number, and I am using Twilio for the SMS messages. The issue is that I am using Swift for my app, and they have no examples in swift currently. This is my code for sending the message:</p>
  
  <pre><code>func sendSMS()
  {
  
      let twilioSID = "AC11ed62fdb971a8f56d9be531a5ce40c2"
      let twilioSecret = "mySecretID"
  
      let fromNumber = "number"
      let toNumber = "number"
      let message = "This is a test message"
  
  
      // Build the request
      let request = NSMutableURLRequest(URL: NSURL(string:"https://\(twilioSID):\(twilioSecret)@api.twilio.com/2010-04-01/Accounts/\(twilioSID)/SMS/Messages")!)
      request.HTTPMethod = "POST"
      request.HTTPBody = "From=\(fromNumber)&amp;To=\(toNumber)&amp;Body=\(message)".dataUsingEncoding(NSUTF8StringEncoding)
  
      // Build the completion block and send the request
      NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) in
          print("Finished")
          if let data = data, responseDetails = NSString(data: data, encoding: NSUTF8StringEncoding) {
              // Success
              print("Response: \(responseDetails)")
          } else {
              // Failure
              print("Error: \(error)")
          }
      }).resume()
  }
  </code></pre>
  
  <p>But whenever I try and run that function, I get this</p>
  
  <pre><code>Finished
  Response: &lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;TwilioResponse&gt;&lt;RestException&gt;&lt;Code&gt;20003&lt;/Code&gt;&lt;Detail&gt;Your AccountSid or AuthToken was incorrect.&lt;/Detail&gt;&lt;Message&gt;Authentication Error - No credentials provided&lt;/Message&gt;&lt;MoreInfo&gt;https://www.twilio.com/docs/errors/20003&lt;/MoreInfo&gt;&lt;Status&gt;401&lt;/Status&gt;&lt;/RestException&gt;&lt;/TwilioResponse&gt;
  </code></pre>
  
  <p>I know that my credentials are correct.....</p>
  
  <p>Is there a better way of doing this? Does anyone have an example out there?</p>