发送指内容的短信
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送指内容的短信相关的知识,希望对你有一定的参考价值。
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
@interface ViewController ()<MFMessageComposeViewControllerDelegate>
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = [NSArray arrayWithObject:@"13888888888"];//指定发送人
controller.body = @"发送短信验证";//指定发送内容
controller.messageComposeDelegate = self;//设置代理
[self presentViewController:controller animated:YES completion:^{
//修改短信界面标题
[[[[controller viewControllers]lastObject]navigationItem ]setTitle:@"修改短信界面"];
}];
}else{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"警告" message:@"该设备不支持发送" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"acton" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
return ;
}];
[alertVC addAction:action];
[self presentViewController:alertVC animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:NO completion:nil];
switch ( result ) {
case MessageComposeResultCancelled:
{
//click cancel button
NSLog(@"取消发送");
}
break;
case MessageComposeResultFailed:// send failed
{
NSLog(@"发送失败");
}
break;
case MessageComposeResultSent:
{
//do something
NSLog(@"已发送出去了");
}
break;
default:
break;
}
}
@end
以上是关于发送指内容的短信的主要内容,如果未能解决你的问题,请参考以下文章