如何在iOS SDK中为用户提供预先编写的SMS消息 [英] How to have a precomposed SMS message for the user in iOS SDK
本文介绍了如何在iOS SDK中为用户提供预先编写的SMS消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Apple Dev网站上的示例代码来学习如何设置预先编写的电子邮件,但是有没有办法类似地设置预先编写的SMS消息?
I used the sample code on the Apple Dev site to learn how to set pre-composed emails, but is there a way to set precomposed SMS messages, similarly?
推荐答案
首先,您必须将框架 MessageUI
添加到您的项目中,并导入库"MessageUI/MessageUI.h"
.然后遵守协议< MFMessageComposeViewControllerDelegate>
.
First you have to add the framework MessageUI
to your project and import the library "MessageUI/MessageUI.h"
. Then conform to the protocol <MFMessageComposeViewControllerDelegate>
.
现在要发送短信:
- (IBAction) sendSMS:(id)sender
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"The body of the SMS you want";
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
要捕获发送操作的结果,请执行以下操作:
To catch the result of the sending operation:
- (void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch(result)
{
case MessageComposeResultCancelled: break; //handle cancelled event
case MessageComposeResultFailed: break; //handle failed event
case MessageComposeResultSent: break; //handle sent event
}
[self dismissModalViewControllerAnimated:YES];
}
这篇关于如何在iOS SDK中为用户提供预先编写的SMS消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文