iOS: showing an alert when getting a call?

无人久伴 提交于 2019-11-29 15:44:16

问题


I would like a local notification to be fired when a call is received (and to show an alert) - is this possible? Can a call event get an app to launch or a notification to be fired?

How is skype fired? With push notifications?

Thanks


回答1:


If your application is running while a call is in place check out the CoreTelephony Framework. The CTCall class provides information about the call state. I have not used this myself but you may find it useful.

extern NSString const *CTCallStateDialing;
extern NSString const *CTCallStateIncoming;
extern NSString const *CTCallStateConnected;
extern NSString const *CTCallStateDisconnected;

Edit:

The CTCallCenter allows you to register for call event state changes. As I said before your application will need to be running to know that something has changed. You may want to request the maximum backgrounding time (I think it is 10 minutes now) when your application is moved to the background. These api's are only available in iOS 4.0 and later.




回答2:


Your application delegate will receive calls to various UIApplicationDelegate protocol methods when various events happen. One of these is the - (void)applicationWillResignActive:(UIApplication *)application method, which is called for incoming calls or text messages, but could be called for other reasons as well.

See the UIApplicationDelegate protocol reference for more information.




回答3:


And, to answer the part of your question nobody's touched yet, Skype is using backgrounding methods specifically meant to keep an app alive in the background to receive VOIP calls. A little bit of it is actually running, waiting to be called. Unless you claim to be a backgrounding app for VOIP or audio purposes, you can't do that--and if you DO claim that, you better be DOING it, or you'll never hit the app store.




回答4:


The best you can do is hook the applicationWillResignActive method, which gets called basically whenever your app loses focus (which happens when a call comes in, but also happens for other reasons, so it's not perfect).

See: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html



来源:https://stackoverflow.com/questions/5395130/ios-showing-an-alert-when-getting-a-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!