技术

如何调用系统发送信息?

2015-11-16  本文已影响26人  952625a28d0d

添加库:

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"]];```

上一篇下一篇

猜你喜欢

热点阅读