如何调用系统发送信息?
2015-11-16 本文已影响26人
952625a28d0d
- 第一种方法
使用MFMessageComposeViewController系统的邮箱系统来发送信息
添加库:
Paste_Image.png引入头文件:
Paste_Image.png代码:
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
// 遵守代理
@interface ViewController ()<MFMailComposeViewControllerDelegate,MFMessageComposeViewControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 启动信息模块
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = @"Message!!!";
[messageComposer setBody:message];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
}
}
// 处理发送结果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
///your stuff here
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end```
- 第二种方法
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:MobileNumber"]];```