zoukankan      html  css  js  c++  java
  • 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];

     

        }

     

    }

     

     

     

     

     

     

     

     

  • 相关阅读:
    ListView的Item被点击和其中的Button被点击同时生效
    Android Canvas绘图详解(图文)
    Android--获取当前系统的语言环境
    自定义seekbar中,thumb被覆盖掉一部分问题
    Android类参考---Fragment
    使用LocalBroadcastManager
    寒哥细谈之AutoLayout全解
    Xcode6中自动布局autolayout和sizeclass的使用
    Swift 2.0初探:值得注意的新特性
    swift调用相机和相册
  • 原文地址:https://www.cnblogs.com/lcl15/p/6483378.html
Copyright © 2011-2022 走看看