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

#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>

ios应用来电监听的更多相关文章

  1. Android来电监听和去电监听

    我觉得写文章就得写得有用一些的,必须要有自己的思想,关于来电去电监听将按照下面三个问题展开 1.监听来电去电有什么用? 2.怎么监听,来电去电监听方式一样吗? 3.实战,有什么需要特别注意地方? 监听 ...

  2. Service之来电监听(失败的案例)

    Service:服务,可以理解成一个运行再后台没有界面的Activity,集成于Seriver,是四大组件之一 Service的继承关系:Service-->ContextWrapper--&g ...

  3. IOS开发:监听来电状态的改变。

    #import <CoreTelephony/CTCallCenter.h> #import <CoreTelephony/CTCall.h> @property(nonato ...

  4. android 呼入电话的监听(来电监听)转

    需要权限: <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 方式一:通过广 ...

  5. 类似吸顶功能解决ios不能实时监听onscroll的触发问题

    问题:近期项目需要一个类似西东功能,当页面向上滚动160px后div固定在顶部 解决方法:首先,想到的是window.onscroll方法 .fixed{position:fixed;-webkit- ...

  6. iOS 键盘的监听 调整view的位置

    iOS在处理键盘的出现和消失时需要监听UIKeyboardWillChangeFrameNotifications/UIKeyboardDidHideNotifications - (void)vie ...

  7. iOS地图 -- 区域监听的实现和小练习

    区域监听用到的方法 [self.mgr startMonitoringForRegion:region]; --> 开启区域监听,没有返回值,在代理方法中得到信息并且处理信息 注:该方法只有用户 ...

  8. 【iOS】通知监听

    下例为:监听文本框  accountField  内容的改变, 当发生改变时, 调用textChange方法(多次).监听结束需要移除通知. - (void)viewDidLoad { [super ...

  9. iOS: 使用KVO监听控制器中数组的变化

    一.介绍: KVO是一种能动态监听到属性值的改变的方式,使用场景非常广泛,这里我只讲如何监听控制器ViewController中数组的变化. 二.了解: 首先我们应该知道KVO是不能直接监听控制器Vi ...

随机推荐

  1. 关于 Unity 中 ModelImporter.optimizeGameObjects

         ModelImporter.optimizeGameObjects 能够优化骨骼动画,将无用的骨骼合并,效率测试官方给出的数据差距比较大( Unity CJ 干货分享:全新的Unity移动游 ...

  2. 【原】Spark中Job的提交源码解读

    版权声明:本文为原创文章,未经允许不得转载. Spark程序程序job的运行是通过actions算子触发的,每一个action算子其实是一个runJob方法的运行,详见文章 SparkContex源码 ...

  3. 【CSS3】Advanced11:Media Queries

    1.Browser-size specific CSS @media screen and (max/min-width:1000px){} 2.Orientation-specific CSS? @ ...

  4. H.264 Profile、Level、Encoder三张简图 (fps = AVCodecContext->time_base.den / AVCodecContext->time_base.num)

    H.264 Profiles Profiles are sets of capabilities. If your black box only supports the Baseline profi ...

  5. hdoj 3861 The King’s Problem【强连通缩点建图&&最小路径覆盖】

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. solrj6.2异常--Expected mime type application/octet-stream but got text/html.

    org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://19 ...

  7. Java 动态生成 复杂 .doc文件

    阅读目录 1.word 里面调整好排版,包括你想生成的动态部分,还有一些不用生成的规则性的文字 2. 将 word 文档保存为 xml 3.用 Firstobject free XML edito 打 ...

  8. 【转】解决Cannot change version of project facet Dynamic web module to 2.5

    http://blog.csdn.net/steveguoshao/article/details/38414145 我们用Eclipse创建Maven结构的web项目的时候选择了Artifact I ...

  9. 利用Continuous Testing实现Eclipse环境自己主动单元測试

    当你Eclipse环境中改动项目中的某个方法时,你可能因为各种原因没有执行单元測试,结果代码提交,悲剧就可能随之而来. 所幸infinitest(http://infinitest.github.io ...

  10. [React] React Fundamentals: Component Lifecycle - Updating

    The React component lifecycle will allow you to update your components at runtime. This lesson will ...