iOS获取系统短信,发送指定短信内容
2016-03-18 19:59
531 查看
现在在开发中应该会经常遇到点击邀请 发送短信给指定人员
点击邀请 弹出短信界面 并发送指定内容,手动点击发送即可
如果只要打开短信界面,并显示号码很简单,一句代码
但要指定短信内容 需要如下方法
1.先引入头文件
2.设置代理
3.实现代理方法
调用方法
点击邀请 弹出短信界面 并发送指定内容,手动点击发送即可
如果只要打开短信界面,并显示号码很简单,一句代码
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@sms://13666666666]];
但要指定短信内容 需要如下方法
1.先引入头文件
#import <MessageUI/MFMessageComposeViewController.h>
2.设置代理
MFMessageComposeViewControllerDelegate
3.实现代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self.mobileContactsVC dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled) { NSLog(@"Message cancelled"); } else if (result == MessageComposeResultSent) { NSLog(@"Message sent"); } else { NSLog(@"Message failed"); } }
调用方法
/** * 指定内容 打开SMS * * @param bodyOfMessage 要发送的内容 * @param recipients 要发送的号码 */ - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients { MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { controller.body = bodyOfMessage; controller.recipients = recipients; controller.messageComposeDelegate = self; [self.mobileContactsVC presentViewController:controller animated:YES completion:nil]; } }``` 只要在需要调用的地方 调用方法即可
[self sendSMS:@"加入工付宝 领取红包金额" recipientList:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@", self.mobileContactsModel.mobile], nil]];
相关文章推荐
- iOS中frame和bounds的区别
- iOSDay10之OC类和对象
- 浅谈ios异步加载
- iOS/mac开发的一些知名个人博客
- IOS SDWebImage实现原理详解
- iOS设置tabbar的显示之 imageWithRenderingMode:
- iOS 开发 发布 证书 详细说明
- HZCoreMannger 使用一句话调用工具类,对数据进行操作
- iOS 自定义录制视频功能
- iOS tableView不让头部和尾部跟随
- iOS 数组/对象排序
- iOS开发之--- NSURLProtocol
- iOS xib与代码一起使用时的视图加载问题
- iOS中new和alloc的区别
- iOS Touch ID 简易开发教程
- iOS解析数据时Error=3840
- ios学习总结(1) -- 创建第一个ios项目
- ios学习总结(1) -- 创建第一个ios项目
- iOS开发之NSThread、NSOperation、GCD三者之间的简略比较
- iOS权限问题