Objective-C Requires Chilkat v11.0.0+
Objective-C
Check message delivery status with Twilio
See more Twilio Examples
Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.
Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.
Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Load an API key for the Twilio account from private application configuration.
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.BasicAuth = YES;
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: @"YOUR_ACCOUNT_SID"];
[url Append: @"/Messages"];
[url Append: @"/"];
[url Append: @"YOUR_MESSAGE_SID"];
[url Append: @".json"];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoJsonObject *reply = [[CkoJsonObject alloc] init];
success = [http HttpNoBody: @"GET" url: [url GetAsString] response: resp];
if ([resp.StatusCode intValue] == 0) {
NSLog(@"%@",@"No HTTP response from Twilio.");
return;
}
BOOL parsed = [reply Load: resp.BodyStr];
if ((success != YES) || ([resp.StatusCode intValue] != 200)) {
NSLog(@"%@%d",@"Twilio returned HTTP ",[resp.StatusCode intValue]);
if ((parsed == YES) && ([[reply JsonTypeOf: @"code"] intValue] == 2)) {
NSLog(@"%@%d%@%@",@"Twilio error: ",[[reply IntOf: @"code"] intValue],@" ",[reply StringOf: @"message"]);
}
return;
}
if (parsed != YES) {
NSLog(@"%@",@"Expected a JSON response from Twilio.");
return;
}
if ([[reply JsonTypeOf: @"status"] intValue] != 1) {
NSLog(@"%@",@"Message status missing from response.");
return;
}
NSLog(@"%@%@",@"Delivery status: ",[reply StringOf: @"status"]);
if (([reply StringOfEquals: @"status" value: @"failed" caseSensitive: YES] == YES) || ([reply StringOfEquals: @"status" value: @"undelivered" caseSensitive: YES] == YES)) {
if ([[reply JsonTypeOf: @"error_code"] intValue] == 2) {
NSLog(@"%@%d",@"Delivery error code: ",[[reply IntOf: @"error_code"] intValue]);
}
if ([[reply JsonTypeOf: @"error_message"] intValue] == 1) {
NSLog(@"%@",[reply StringOf: @"error_message"]);
}
}