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开发者_JAVA技巧 notifications?
Thanks
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.
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.
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.
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
精彩评论