简体   繁体   English

检测来电

[英]Detect incoming phone calls

I need to determine when an incoming phone call arrives. 我需要确定来电时间何时到来。 I know that applicationWillTerminate will be called if the user takes the call and applicationWillResignActive when the popup with the confirmation message for the call appears, however: 我知道如果用户接听电话时将调用applicationWillTerminate,并且当出现带有呼叫确认消息的弹出窗口时,将调用applicationWillResignActive:
-applicationWillTerminate is also called when the app exits by user request or battery is about to die 当应用程序按用户请求退出或电池即将耗尽时,也会调用-applicationWillTerminate
-applicationWillResignActive is also called when a UIViewAlert is shown. 当显示UIViewAlert时,也会调用-applicationWillResignActive。

Thanks 谢谢

简而言之 - 不,您无法确定应用程序中是否有来电或其他类型的中断。

I found this article on handling incoming calls; 我找到了关于处理来电的这篇文章; terminating resuming and persisting state,. 终止恢复和持久状态。

It might help you.. 它可能会帮助你..

http://www.tomwhitson.co.uk/blog/2009/04/handling-interuptions-to-your-app/ http://www.tomwhitson.co.uk/blog/2009/04/handling-interuptions-to-your-app/

(void)applicationWillResignActive:(UIApplication *)application{
        //our app is going to loose focus since thier is an incoming call
        [self pauseGame];
}

(void)applicationDidBecomeActive:(UIApplication *)application{
        //the user declined the call and is returning to our app
        [self resumeGame];
}

(void)applicationWillTerminate:(UIApplication*)application{
        //the user answered the call (or quit the app) so save the
        //game as we are shutting down
        [self saveGameState];
}

I know this questions is really old, but in case someone else reach this question just like me, there is an audio session delegate to detect if the audio will be interrupted (mainly by a Phone call). 我知道这些问题确实很旧,但是如果其他人像我一样得到这个问题,会有一个音频会话代表来检测音频是否会被中断(主要是通过电话)。

For any app playing audio this approach works for detecting incoming iphone calls. 对于任何播放音频的应用程序,此方法适用于检测传入的iphone呼叫。

Here is a link to Apple documentation for: Handling Audio Interruptions 以下是Apple文档的链接: 处理音频中断

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM