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

  • 相关阅读:
    织梦DedeCms网站首页不生成html文件动态显示方法
    PHP7.0下安装DEDE织梦 出现 GD不支持的解决方法
    DEDECMS5.7支持伪静态的方法
    DEDECMS全站伪静态设置方法
    设置 SSH 通过密钥登录
    Windows安装OpenSSH服务
    VS Code远程开发工具错误-找不到SSH安装
    帝国CMS自定义列表的排序
    帝国CMS灵动标签e:loop的使用方法
    cisco 3750交换机堆叠后配置恢复方法
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/5993552.html
Copyright © 2011-2022 走看看