Rocky
Rocky

Reputation: 289

iPhone: Can an app detect when the phone receives a call and come back to the app?

I am checking it with

- (void)applicationWillEnterForeground:(UIApplication *)application

when it comes back to the app.

But this one doesn't detect when the user declines the call. Is there anyway to detect even when the user declines the call?

Upvotes: 1

Views: 840

Answers (3)

tim k
tim k

Reputation: 162

I think what you want is to detect when the app is coming back into an active state. There are two delegate methods for this:

applicationWillEnterForeground: Tells the delegate that the application is about to enter the foreground.

- (void)applicationWillEnterForeground:(UIApplication *)application

and

applicationDidBecomeActive: Tells the delegate that the application has become active.

- (void)applicationDidBecomeActive:(UIApplication *)application

more info in the documentation of UIApplicationDelegate

Upvotes: 1

CSolanaM
CSolanaM

Reputation: 3368

Maybe you could use the following notifications, in your case, the second one:

Add CoreTelephony.framework to your project and:

#import <CoreTelephony/CTCall.h>

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];

Upvotes: 4

JeffN
JeffN

Reputation: 1605

There isn't a way that I know of to tell when the call is declined. But this method is called when the user gets a call:

    - (void)applicationWillResignActive:(UIApplication *)application {
}

Upvotes: 0

Related Questions