首先
#import <MessageUI/MessageUI.h>
然后
MFMessageComposeViewControllerDelegate
主要在这里
- (void)showMessageView
{
if( [MFMessageComposeViewController
canSendText] ){
MFMessageComposeViewController * controller = [[MFMessageComposeViewController
alloc]init];
//autorelease];
//controller.recipients = [NSArray arrayWithObject:@"10010"];
controller.body =
@"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
controller.messageComposeDelegate =
self;
[self
presentViewController:controller animated:YES
completion:nil];
[[[[controller viewControllers]
lastObject] navigationItem]
setTitle:@"XXXXXXXXXXX"];//修改短信界面标题
}else{
[self
alertWithTitle:@"提示信息"
msg:@"设备没有短信功能"];
}
}
提示信息
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:NO
completion:nil];//关键的一句
不能为YES
switch ( result ) {
case
MessageComposeResultCancelled:
[self
alertWithTitle:@"提示信息"
msg:@"发送取消"];
break;
case
MessageComposeResultFailed:// send failed
[self
alertWithTitle:@"提示信息"
msg:@"发送成功"];
break;
case
MessageComposeResultSent:
[self
alertWithTitle:@"提示信息"
msg:@"发送失败"];
break;
default:
break;
}
}