• ios 调用系统打电话和发消息的功能


    1.打电话

        

       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",@"13027621806"]]];

     

    2.发信息

     方法一:调用的方法非常的简单,但是不能够回到自己的应用,是程序外调用系统发短信

        [[UIApplication sharedApplicationopenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",@"13027621806"]]];

     

     方法二:程序内调用系统发短信,操作完成后可以回到自己的app

       首先要导入支持发短信的UI框架  MessageUI.framework

       在使用的类里带入头文件    #import<MessageUI/MessageUI.h>

       该类还要遵循MFMessageComposeViewControllerDelegate的代理

       调用方法如下

         【self showMessageView:[NSArray arrayWithObjects:self.peopleModel.telNumber, nil] title:@"test" body:@"这是测试用短信,勿回复!"];

     

       具体代码入下

     

     

    -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

     

    {

     

        [self dismissViewControllerAnimated:YES completion:nil];

     

        switch (result) {

     

            case MessageComposeResultSent:

     

                //信息传送成功

     

                

     

                break;

     

            case MessageComposeResultFailed:

     

                //信息传送失败

     

                

     

                break;

     

            case MessageComposeResultCancelled:

     

                //信息被用户取消传送

     

                

     

                break;

     

            default:

     

                break;

     

        }

     

    }

     

    -(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body

     

    {

     

        if( [MFMessageComposeViewController canSendText] )

     

        {

     

            MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];

     

            controller.recipients = phones;

     

            controller.navigationBar.tintColor = [UIColor redColor];

     

            controller.body = body;

     

            controller.messageComposeDelegate = self;

     

            [self presentViewController:controller animated:YES completion:nil];

     

            [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题

     

        }

     

        else

     

        {

     

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"

     

                                                            message:@"该设备不支持短信功能"

     

                                                           delegate:nil

     

                                                  cancelButtonTitle:@"确定"

     

                                                  otherButtonTitles:nil, nil];

     

            [alert show];

     

        }

     

    }

     

     

     

     

     

     

     

     

  • 相关阅读:
    C#中的Virtual
    DevExpress控件中LayoutControl的使用
    汉字获取首字母拼音
    工具类
    C# 根据时间创建文件夹
    图片延迟加载
    IIS日志分析的作用
    SQL2008R2 无法读取此系统上以前注册的服务器的列表--网上方法不可行
    windows 服务器系统日志分析及安全
    301跳转
  • 原文地址:https://www.cnblogs.com/lcl15/p/6483378.html
Copyright © 2020-2023  润新知