博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios应用来电监听
阅读量:5298 次
发布时间:2019-06-14

本文共 2776 字,大约阅读时间需要 9 分钟。

先导入这两个头文件,库文件不用导可以

#import <CoreTelephony/CTCallCenter.h>

#import <CoreTelephony/CTCall.h>

//申明电话类属性,必须申明成成品属性,不然没效果;

@property(nonatomic,strong)CTCallCenter *callCenter;

 

//如下两个方法中监听:

- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

 

    self.callCenter = [[CTCallCenter alloc] init];

    self.callCenter.callEventHandler=^(CTCall* call)

    {

        if (call.callState == CTCallStateDisconnected)

        {

            NSLog(@"-applicationWillResignActive----挂断");   //挂断

            //            self.viewController.signalStatus=YES;

        }

        else if (call.callState == CTCallStateConnected)

        {

            NSLog(@"--applicationWillResignActive---连通了"); //联通了

        }

        

        else if(call.callState == CTCallStateIncoming)

        {

            NSLog(@"applicationWillResignActive Call is incoming");

            //self.viewController.signalStatus=NO;

        }

        

        else if (call.callState ==CTCallStateDialing)

        {

            NSLog(@"--applicationWillResignActive----拨号");  //拨号

        }

        else

        {

            NSLog(@"applicationWillResignActive Nothing is done?");

        }

    };

    

    NSLog(@"applicationWillResignActive:%@",application);

 

}

 

 

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

 

    self.callCenter = [[CTCallCenter alloc] init];

    self.callCenter.callEventHandler=^(CTCall* call)

    {

        if (call.callState == CTCallStateDisconnected)

        {

            NSLog(@"-applicationDidBecomeActive----挂断");   //挂断

            //            self.viewController.signalStatus=YES;

        }

        else if (call.callState == CTCallStateConnected)

        {

            NSLog(@"--applicationDidBecomeActive---连通了"); //联通了

        }

        

        else if(call.callState == CTCallStateIncoming)

        {

            NSLog(@"applicationDidBecomeActive Call is incoming");

            //self.viewController.signalStatus=NO;

        }

        

        else if (call.callState ==CTCallStateDialing)

        {

            NSLog(@"--applicationDidBecomeActive----拨号");  //拨号

        }

        else

        {

            NSLog(@"applicationDidBecomeActive Nothing is done?");

        }

    };

    NSLog(@"applicationDidBecomeActive:%@",application);

}

 

//结合上面的打印顺序,app方法的调用顺序如下:

    //来电时> applicationDidBecomeActive Call is incoming > applicationWillResignActive:

    //挂断>  applicationWillResignActive----挂断 > applicationDidBecomeActive:<UIApplication: 0x137609010>

    //机主接听>  --applicationWillResignActive---连通了

    //通话结束> -applicationWillResignActive----挂断 > applicationDidBecomeActive:<UIApplication: 0x137609010>

转载于:https://www.cnblogs.com/haohao-developer/p/5884780.html

你可能感兴趣的文章
Spring 自动装配;方法注入
查看>>
浏览器的判断;
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
uva 10791
查看>>
python的字典(dict)的键值对存储规则
查看>>
ubuntu18 tensorflow cpu fast_rcnn
查看>>
PageHelper在Mybatis中的使用
查看>>
POJ 1742 Coins
查看>>
Leetcode 589. N-ary Tree Preorder Traversal
查看>>
ADO.Net——增、删、改、查
查看>>
thinking back no11
查看>>
机器学习/深度学习/其他开发环境搭建记录
查看>>
xml.exist() 实例演示
查看>>
判断是否为空然后赋值
查看>>
中标麒麟QT+ODBC+人大金仓开发环境配置
查看>>
Silverlight WCF RIA服务(九)Domain Service 2
查看>>
JSON的结构
查看>>
NopCommerce换主题这件小事
查看>>
zabbix监控日志文件
查看>>
mysql查询数据库中每一张表的内存大小
查看>>