设为首页 加入收藏

TOP

打电话、发短信、web以及发邮件(二)
2017-10-13 10:29:14 】 浏览:5597
Tags:打电话 短信 web 以及 邮件
05
result枚举 106 */ 107 NSLog(@"%d",result); 108 109 //注:别忘了回到应用中 110 [controller dismissViewControllerAnimated:YES completion:^{ 111 NSLog(@"短信控制器消失完成后代码块"); 112 }]; 113 114 } 115 116 - (IBAction)sendEmail:(id)sender { 117 118 //方式1 119 // NSString *str = [NSString stringWithFormat:@"mailto://%@",self.emailTextField.text]; 120 // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; 121 122 //方式2 123 //判断是否能发送邮件 124 if (![MFMailComposeViewController canSendMail]) { 125 NSLog(@"不能发送邮件"); 126 return; 127 } 128 //创建mail控制器对象 129 MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init]; 130 //设置邮件主题 131 [vc setSubject:@"我爱你"]; 132 //设置邮件发送内容 第二个参数支持HTML格式 133 [vc setMessageBody:@"基本的电话、邮件、短信" isHTML:YES]; 134 //设置收件人列表 135 [vc setToRecipients:@[@"*******@qq.com"]]; 136 //设置抄送人列表 137 [vc setCcRecipients:@[@"********@qq.com",@"********@163.com"]]; 138 //设置邮件代理 139 vc.mailComposeDelegate = self; 140 //显示邮件控制器 141 [self presentViewController:vc animated:YES completion:^{ 142 NSLog(@"跳转完成后执行代码块"); 143 }]; 144 145 146 } 147 148 - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 149 150 /* 151 result枚举类型 152 MFMailComposeResultCancelled, 取消 153 MFMailComposeResultSaved, 保存 154 MFMailComposeResultSent, 发送 155 MFMailComposeResultFailed 失败 156 */ 157 NSLog(@"%d",result); 158 159 [controller dismissViewControllerAnimated:YES completion:^{ 160 NSLog(@"邮箱控制器消失完成后代码块"); 161 }]; 162 163 } 164 @end

打电话、发短信、web以及发邮件

另外补充一下,用下面的个人感觉更好一些!上面的UIWebView好像弹框的速度有点慢 自己弹框一下更方便一些

- (void)callAction:(NSString *)phone{

    NSMutableString* str1=[[NSMutableString alloc]initWithString:phone];//存在堆区,可变字符串

    [str1 insertString:@"-"atIndex:3];//把一个字符串插入另一个字符串中的某一个位置

    [str1 insertString:@"-"atIndex:8];//把一个字符串插入另一个字符串中的某一个位置

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:str1 message:nil preferredStyle:UIAlertControllerStyleAlert];

    // 设置popover指向的item

    alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;

    // 添加按钮

    [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

        NSLog(@"点击了呼叫按钮");

        NSString* phoneStr = [NSString stringWithFormat:@"tel://%@",phone];

        if ([phoneStr hasPrefix:@"sms:"] || [phoneStr hasPrefix:@"tel:"]) {

            UIApplication * app = [UIApplication sharedApplication];

            if ([app canOpenURL:[NSURL URLWithString:phoneStr]]) {

                [app openURL:[NSURL URLWithString:phoneStr]];

            }

        }

 

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇用UICollectionView实现无限轮播图 下一篇多线程之NSOperation和NSOperatio..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目