本文主要是介绍iOS开发之发送信息 邮件 打电话,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
创建MFMessageComposeViewController对象。
设置收件人recipients、
信息正文body,
主题subject
附件attachments(可以通过canSendSubject、canSendAttachments方法判断是否支持)
设置代理messageComposeDelegate(注意这里不是delegate属性,因为delegate属性已经留给UINavigationController,MFMessageComposeViewController没有覆盖此属性而是重新定义了一个代理),实现代理方法获得发送状态。
isSupportedAttachmentUTI 判断是否支持统一标识附件
根据URL路径和添加附件,返回YES表示添加成功
- (BOOL)addAttachmentURL:(NSURL *)attachmentURL withAlternateFilename:(NSString *)alternateFilename;
根据Data数据添加附件
- (BOOL)addAttachmentData:(NSData *)attachmentData typeIdentifier:(NSString *)uti filename:(NSString *)filename;
#import"ViewController.h"
//引入框架
#import
@interfaceViewController()
@property(nonatomic,strong)UIWebView*webView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton*phoneButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
phoneButton.frame=CGRectMake(100,100,100,100);
[phoneButtonsetTitle:@"打电话"forState:UIControlStateNormal];
[phoneButtonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
[phoneButtonaddTarget:selfaction:@selector(phoneButtonAction:)forControlEvents:UIControlEventTouchUpInside];
UIButton*messageButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
messageButton.frame=CGRectMake(100,240,100,100);
[messageButtonsetTitle:@"发信息"forState:UIControlStateNormal];
[messageButtonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
[messageButtonaddTarget:selfaction:@selector(messageButtonAction:)forControlEvents:UIControlEventTouchUpInside];
UIButton*emailButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
emailButton.frame=CGRectMake(100,400,100,100);
[emailButtonsetTitle:@"发邮件"forState:UIControlStateNormal];
[emailButtonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
[emailButtonaddTarget:selfaction:@selector(emailButtonAction:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:phoneButton];
[self.viewaddSubview:messageButton];
[self.viewaddSubview:emailButton];
}
//电话有三种方法
- (void)phoneButtonAction:(UIButton*)button
{
//法一:没有弹窗提示直接运行不能回到原来的应用程序
// tel://是代码规范
// NSURL *url = [NSURL URLWithString:@"tel://15385548670"];
// [[UIApplication sharedApplication] openURL:url];
//法二:有弹窗提示可以回到原来的应用程序
// telprompt这个是苹果的私有方法应用程序中如果使用了这个方法审核会被驳回
// NSURL *url = [NSURL URLWithString:@"telprompt://15385548670"];
// [[UIApplication sharedApplication] openURL:url];
//法三:借助webView打电话有弹窗会回到原来的应用程序建议使用
//懒加载不要将webView添加到self.view如果添加的话会遮挡原应用程序
if(_webView==nil) {
_webView= [[UIWebViewalloc]init];
}
NSURL*url = [NSURLURLWithString:@"tel://15385548670"];
//创建一个请求
NSURLRequest*request = [NSURLRequestrequestWithURL:url];
//通过请求加载webView
[_webViewloadRequest:request];
}
// message和email需要需要添加一个一个框架
- (void)messageButtonAction:(UIButton*)button
{
if([MFMessageComposeViewControllercanSendText]) {
//初始化一个控制器
MFMessageComposeViewController*messageVC = [[MFMessageComposeViewControlleralloc]init];
//设置短信内容
//设置收件人可设置多个
messageVC.recipients=@[@"15385548670"];
//设置短信内容
messageVC.body=@"
这篇关于iOS开发之发送信息 邮件 打电话的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!