Objective-C Requires Chilkat v11.0.0+
Objective-C
Send an MMS with Twilio using a media URL
See more Twilio Examples
Send an image and an optional caption from an MMS-capable Twilio number. Supply an MMS-supported destination in E.164 format and replace the example media URL with an HTTPS URL Twilio can fetch. The host must handle HEAD and GET and return the correct Content-Type for the file.
Live send. With live credentials and valid inputs, this request submits a billable message. Save the Message SID to check delivery later. Supported media types and size limits.
Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoHttpRequest.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.BasicAuth = YES;
// Load the owning Account SID and an API key from application configuration.
NSString *accountSid = @"YOUR_ACCOUNT_SID";
http.Login = @"YOUR_API_KEY_SID";
http.Password = @"YOUR_API_KEY_SECRET";
CkoStringBuilder *url = [[CkoStringBuilder alloc] init];
[url Append: @"https://api.twilio.com/2010-04-01/Accounts/"];
[url Append: accountSid];
[url Append: @"/Messages.json"];
// Add raw field values. Chilkat form-encodes them, including the + in a phone number.
CkoHttpRequest *req = [[CkoHttpRequest alloc] init];
req.HttpVerb = @"POST";
req.ContentType = @"application/x-www-form-urlencoded";
[req AddParam: @"From" value: @"YOUR_MMS_ENABLED_NUMBER"];
[req AddParam: @"To" value: @"RECIPIENT_E164_NUMBER"];
// Supply a URL for the file itself so Twilio can retrieve the media.
[req AddParam: @"MediaUrl" value: @"https://media.example.com/photo.jpg"];
[req AddParam: @"Body" value: @"Photo attached."];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoJsonObject *reply = [[CkoJsonObject alloc] init];
success = [http HttpReq: [url GetAsString] request: req response: resp];
if ([resp.StatusCode intValue] == 0) {
NSLog(@"%@",http.LastErrorText);
return;
}
BOOL parsed = [reply Load: resp.BodyStr];
if ((success != YES) || ([resp.StatusCode intValue] != 201)) {
NSLog(@"%@%d",@"HTTP ",[resp.StatusCode intValue]);
if ((parsed == YES) && ([reply HasMember: @"code"] == YES)) {
NSLog(@"%@%d%@%@",@"Twilio error ",[[reply IntOf: @"code"] intValue],@": ",[reply StringOf: @"message"]);
}
return;
}
if (parsed != YES) {
NSLog(@"%@",@"Expected a JSON response.");
return;
}
if (([[reply JsonTypeOf: @"sid"] intValue] != 1) || ([[reply JsonTypeOf: @"status"] intValue] != 1)) {
NSLog(@"%@",@"The create response is missing the message SID or status.");
return;
}
NSLog(@"%@%@",@"Message SID: ",[reply StringOf: @"sid"]);
NSLog(@"%@%@",@"Initial status: ",[reply StringOf: @"status"]);