在iPhone中以编程方式发送短信 [英] sending sms programmatically in iphone

查看:81
本文介绍了在iPhone中以编程方式发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程方式将短信发送到iPhone中的联系人列表中选择的特定号码?

How can you send an SMS programmatically to a particular number selected in the contact list in iPhone?

推荐答案

MFMessageComposeController .

要发送短信,您正在查看类似这样的内容:

To send an SMS, you're looking at something like this:

#import <MessageUI/MessageUI.h>
@interface myClass : NSObject <MFMessageComposeViewControllerDelegate>{
}
@end

@implementation

-(void)sendMessage{
    if([MFMessageComposeController canSendText]){
        MFMessageComposeController *smsComposer =
[[MFMessageComposeController alloc] init]; smsComposer.recipients = [NSArray arrayWithObject:@"12345678"]; smsComposer.body = @"SMS BODY HERE"; smsComposer.delegate = self; [self presentModalViewController:smsComposer animated:NO]; } else{ //You probably want to show a UILocalNotification here. } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result{ /* You can use the MessageComposeResult to determine what happened to the
message. I believe it tells you about sent, stored for sending later, failed
or cancelled. */ [self dismissModalViewControllerAnimated:NO]; } @end

这是目前从您的应用发送短信的唯一方法.除非您只想打开SMS应用程序.如果您不担心邮件的正文,可以执行以下操作:

That's the only way to send SMSs from your app at the moment. Unless you just want to open the SMS app. If you aren't worried about the body of the message, you can do this:

NSString *smsURL = @"sms:12345678";
NSURL *url = [NSURL URLWithString:smsURL];
[[UIApplication sharedApplication] openURL:url];

这篇关于在iPhone中以编程方式发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆