Send MMS using Twilio in ios

风流意气都作罢 提交于 2019-12-07 19:06:01

问题


I want to send MMS using Twilio. I am request one twilio url which is work fine on SMS but not MMS and I want to know what should change so i am sending MMS using Twilio in iOS. Here is my code.

NSLog(@"Sending request.");

// Common constants
NSString *kTwilioSID =@"Twilio SID";
NSString *kTwilioSecret =@"Twilio Secret";
NSString *kFromNumber = @"From Phone Number";
NSString *kToNumber = @"To Phone number";
NSString *kMessage=@"Hello This is Pintu vasani";

// Build request
NSString *urlString = [NSString stringWithFormat:@"https://%@:%@@api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages", kTwilioSID, kTwilioSecret, kTwilioSID];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];

// Set up the body  MediaUrl
NSString *bodyString = [NSString stringWithFormat:@"From=%@&To=%@&Body=%@", kFromNumber, kToNumber, kMessage];
NSData *data = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
NSError *error;
NSURLResponse *response;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

// Handle the received data
if (error) {
    NSLog(@"Error: %@", error);
} else {
    NSString *receivedString = [[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"Request sent. %@", receivedString);
}

回答1:


Twilio developer evangelist here.

You seem to be using the old, deprecated Sms resource which doesn't support MMS. You really want to be using the Messages resource which does work.

On a separate note, I would not recommend making API calls directly to Twilio from your iOS application (or any other client application). To do this you would need to embed your Twilio credentials within the application which is dangerous. I would recommend sending the SMS/MMS from a server side application as in this example.



来源:https://stackoverflow.com/questions/29891307/send-mms-using-twilio-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!