问题描述
我正在开发一个简单的应用程序,在该应用程序中,我需要以编程方式向我的朋友发送短信. 因此,请在下面编写用于发送短信的代码.
I am working on a simple application in which I need send sms programmatically to my friends. so write below code for sending sms .
MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init]autorelease];
if([MFMessageComposeViewController canSendText])
{
picker.messageComposeDelegate = self;
picker.recipients =[NSArray arrayWithObject:@"123"];
picker.body=@"hello";
[self presentModalViewController:picker animated:YES];
}
但是我不想加载消息选择器并将短信发送给朋友.//[self presentModalViewController:picker animation:YES];
是否可以在不单击发送按钮的情况下发送短信.
but I do not want to load message picker and send sms to friends.// [self presentModalViewController:picker animated:YES];
is it possible to send sms without click in send button.
推荐答案
iOS API中可用的两个选项是:
The two options available in the iOS API are:
-
MFMessageComposeViewController
-需要用户确认 -
sms://
URL-需要用户确认
MFMessageComposeViewController
- requires user confirmationsms://
URLs - requires user confirmation
如果要执行其他操作,则需要与SMS网关提供商一起设置基于网络的服务,并通过该服务发送消息.我曾经与具有HTTP POST接口的提供程序一起使用,该接口使用起来很简单.这有几个重要的区别:
If you want to do something else, you'll need to set up a network-based service with an SMS gateway provider and send messages via that. I used to work with such a provider that had an HTTP POST interface, which would be simple enough to use. That comes with a couple of important differences:
- SMS实际上是由网关服务器而非手机发送的(尽管您通常可以重写发件人ID并将消息记入手机所有者的账单)
- 您需要为使用该服务付费,其中可能包括为每条消息付费(或更可能是每1,000条消息付费)
还请注意,在审核您的应用程序时,尤其是如果付费的用户,可能会不赞成代表您的用户发送SMS而无需确认.
Also note that sending SMS on your users' behalf without confirmation might be frowned upon when your app is reviewed, especially if they're billed for.
这篇关于iPhone 4.0以编程方式发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!