1、添加頭文件
- #import <CoreTelephony/CTCallCenter.h>
- #import <CoreTelephony/CTCall.h>
2、定義監(jiān)聽對(duì)象
- CTCallCenter *_callCenter;
3、創(chuàng)建監(jiān)聽對(duì)象
- _callCenter = [CTCallCenternew];
- _callCenter.callEventHandler = ^(CTCall *call){
- NSLog(@"電話狀態(tài)是:%@",call.callState);
- };
4、關(guān)于進(jìn)入后臺(tái)時(shí)不提示的問題
第一種:iOS9以后需要在plist文件中的Required background modes下添加App provides Voice over IP services項(xiàng)(iTunes Connect審核可能會(huì)被拒絕,不推薦)
第二種:通過線程方法保證程序在后臺(tái)運(yùn)行時(shí)不被掛起,這樣就能避免被后臺(tái)掛起時(shí)監(jiān)聽不到來電了。
更多建議: