zoukankan      html  css  js  c++  java
  • 打电话,发短信,发邮件,app跳转

    1.打电话

    - (IBAction)callPhone1:(id)sender {
        NSURL *url = [NSURL URLWithString:@"tel://18500441739"];
        [[UIApplication sharedApplication] openURL:url];
    }
    - (IBAction)callPhone2:(id)sender {
        NSURL *url = [NSURL URLWithString:@"telprompt://18500441739"]; 
    [[UIApplication sharedApplication] openURL:url]; }
    - (IBAction)callPhone3:(id)sender {
        if (_webView == nil) {
            _webView = [[UIWebView alloc] initWithFrame:CGRectZero];
        }
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://18500441739"]]];
    }

      推荐使用第三种,第一个为私有API,第二个无法回到原来app

    2.发短信

    - (IBAction)sendMsg:(id)sender {
        NSURL *url = [NSURL URLWithString:@"sms://18500441739"];
        [[UIApplication sharedApplication] openURL:url];
    }
    - (IBAction)sendWithMsg:(id)sender {
        /*  必须要导入<MessageUI/MessageUI.h> */
        MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
        /*  消息内容  */
        vc.body = @"吃饭了没?";
        /*  收到消息的人列表  */
        vc.recipients = @[@"18500441739",@"15342777049"];
        /*  MFMessageComposeViewControllerDelegate  */
        vc.messageComposeDelegate = self;
        [self presentViewController:vc animated:YES completion:nil];
    }

       建议使用第二种,第二个可以预编辑文字和发送列表发送完了以后会有代理方法调用

    #pragma mark - MFMessageComposeViewControllerDelegate
    -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
        [controller dismissViewControllerAnimated:YES completion:nil];
        if (result == MessageComposeResultCancelled) {
            NSLog(@"取消发送");
        }else if (result == MessageComposeResultFailed){
            NSLog(@"发送失败");
        }else if(result == MessageComposeResultSent){
            NSLog(@"发送成功");
        }else{
            NSLog(@"未知情况");
        }
    }

    3.发送邮件

    - (IBAction)sendEmail:(id)sender {
        NSURL *url = [NSURL URLWithString:@"mailto://aaaa61134@qq.com"];
        [[UIApplication sharedApplication] openURL:url];
    }
    - (IBAction)sendEmailWithMsg:(id)sender {
        NSLog(@"%@",[self class]);
        
        if (![MFMailComposeViewController canSendMail]) {
            NSLog(@"yes");
            return;
        }
        MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
        /*  收件人列表  */
        [vc setToRecipients:@[@"2542461134@qq.com",@"22422061134"]];
        /*  抄送人列表  */
        [vc setCcRecipients:@[@"12763456@qq.com"]];
        /*  密送人列表  */
        [vc setBccRecipients:@[@"233r@qq.com",@"2525234@163.com"]];
        /*  设置代理   MFMailComposeViewControllerDelegate*/
        [vc setMailComposeDelegate:self];
        /*  发送主题  */
        [vc setSubject:@"会议"];
        /*  发送内容,是否为HTML文档  */
        [vc setMessageBody:@"测试发邮件功能" isHTML:NO];
        
        /*  添加附件  */
        UIImage *image = [UIImage imageNamed:@"IMG_0993"];
        NSData *data = UIImagePNGRepresentation(image);
        [vc addAttachmentData:data mimeType:@"image/png" fileName:@"首页.png"];
        
        /*  跳转页面  */
        [self presentViewController:vc animated:YES completion:nil];
    
    }

     推荐 第二种方法,第二种方法也有代理方法的调用

    #pragma mark - MFMailComposeViewControllerDelegate
    -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
        [controller dismissViewControllerAnimated:YES completion:nil];
        if (result == MFMailComposeResultCancelled) {
            NSLog(@"取消发送");
        }else if (result == MFMailComposeResultSent){
            NSLog(@"发送成功");
        }else if (result == MFMailComposeResultSaved){
            NSLog(@"保存邮件");
        }else if (result == MFMailComposeResultFailed){
            NSLog(@"发送失败");
        }else{
            NSLog(@"发送异常");
        }
    }

    4.跳转其他app

      a.跳转浏览器

    /*  跳入浏览器  */
    - (IBAction)intoBorwer:(UIButton *)sender {
        /*  
         如果想打开一些常见文件,比如html、txt、PDF、PPT等,都可以使用UIWebView打开
         只需要告诉UIWebView文件的URL即可
         
         至于打开一个远程的共享资源,比如http协议的,也可以调用系统自带的Safari浏览器
         */
        NSLog(@"%@",sender.titleLabel.text);
        NSString *urlStr = [NSString stringWithFormat:@"http://%@",sender.titleLabel.text];
        NSURL *url = [NSURL URLWithString:urlStr];
        [[UIApplication sharedApplication] openURL:url];
    }

      b.跳转到其他app

    /*  跳入到其他的程序  */
    - (IBAction)intoOtherApp:(id)sender {
        /*  在要跳入的app中设置  URL Types
         1.打开原文件
         2.选择Info.Plist文件
         3.添加URL types
         4.点开URL types 将URL identifier的值设为 ios.defaults.com
         5.在URL types中添加URL Schemes,并将其值设为 who
         6.访问的url为 who://ios.defaults.com
         */
        NSURL *url = [NSURL URLWithString:@"yds://ios.hgl.org"];
        [[UIApplication sharedApplication] openURL:url];
    }
  • 相关阅读:
    软件测试经典面试题汇总测试…(转载)
    loadrunner录制时弹出invalid application path
    【转】性能测试知多少:性能分析与…(转载)
    loadrunner小知识累积(转载)
    selenium定位方法总结
    [testng]Cannot find class in classpath
    java工程名前有红色感叹号
    jenkins slave节点问题总结
    scrapy爬虫框架
    Python监听鼠标键盘事件
  • 原文地址:https://www.cnblogs.com/gulong/p/4722822.html
Copyright © 2011-2022 走看看