在iOS中使用Twilio发送彩信 [英] Send MMS using Twilio in ios
问题描述
我想使用 Twilio 发送彩信.我要求提供一个twilio网址,该网址在SMS上可以正常工作,但不能在MMS上正常工作,我想知道应该更改什么,因此我使用 Twilio 在iOS中.这是我的代码.
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);
}
推荐答案
此处是Twilio开发人员的福音.
Twilio developer evangelist here.
您似乎正在使用旧的弃用的Sms资源,它没有不支持彩信.您确实想使用有效的消息资源.
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.
另外,我不建议您从iOS应用程序(或任何其他客户端应用程序)直接对Twilio进行API调用.为此,您需要将Twilio凭据嵌入到应用程序中,这很危险.我建议像
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.
这篇关于在iOS中使用Twilio发送彩信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!