• ios电话拨打进行监听电话状态


    #import "ViewController.h"

    #import <CoreTelephony/CTCallCenter.h>

    #import <CoreTelephony/CTCall.h>

    @interface ViewController ()

    @property (nonatomic, strong) CTCallCenter *center;

    @property (nonatomic, strong) UIWebView * callView;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 50)];

        btn.backgroundColor = [UIColor redColor];

        [btn setTitle:@"拨打电话" forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(callBack) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

        

        _center = [[CTCallCenter alloc] init];

        _center.callEventHandler = ^(CTCall *call) {

            if ([call.callState isEqualToString:CTCallStateDisconnected])

            {

                NSLog(@"挂断了电话咯Call has been disconnected");

            }

            else if ([call.callState isEqualToString:CTCallStateConnected])

            {

                NSLog(@"电话通了Call has just been connected");

            }

            else if([call.callState isEqualToString:CTCallStateIncoming])

            {

                NSLog(@"来电话了Call is incoming");

                

            }

            else if ([call.callState isEqualToString:CTCallStateDialing])

            {

                NSLog(@"正在播出电话call is dialing");

            }

            else

            {

                NSLog(@"嘛都没做Nothing is done");

            }

        };

        // Do any additional setup after loading the view, typically from a nib.

    }

    - (void)callBack{

        NSString * str=[[NSString alloc] initWithFormat:@"tel:%@",@"18310501773"];

        UIWebView * callWebview = [[UIWebView alloc] init];

        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];

        [self.view addSubview:callWebview];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    linux下vim更改注释颜色
    使用web3j工具生成java版本的智能合约
    Pycharm增加新安装Python的路径
    Python第三弹--------文件和异常
    (转)以太坊(Ethereum)创世揭秘 以太坊(Ethereum)创世揭秘
    (转)以太坊(Ethereum)全零地址(0x000000...)揭秘
    (转)Java大数操作(BigInteger、BigDecimal)
    关于SimpleDateFormat时间转换总是显示1970年的问题
    以太坊abi
    (转)以太坊私链的挖矿速度与难度值的关系
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/5993552.html
Copyright © 2020-2023  润新知