Lauri Larjo
Lauri Larjo

Reputation: 314

How to recognize if app was reloaded after phone call?

I have a program which automatically launches a phone call when program is started. This is implemented in AppDelegate's "applicationDidFinishLaunching"-method.

Problem is: When phone call ends and my app automatically launches again, it restarts that loop and phone call is started again.

How to recognize if app was returned from that call? Or somehow easily save the state or variables of the program that define if the call was already made?

I just started iPhone programming and this came up.

Upvotes: 3

Views: 679

Answers (3)

Bushra Shahid
Bushra Shahid

Reputation: 3579

You can use UIWebview to make a call like explained in this question:

Return to app behavior after phone call different in native code than UIWebView

and use core telephony to check if call ended:

//before calling loadRequest:
CTCallCenter *callCenter.callEventHandler=^(CTCall* call) {

        if(call.callState == CTCallStateDialing)
        {
            //The call state, before connection is established, when the user initiates the call.
            NSLog(@"Dialing");
        }
        if(call.callState == CTCallStateIncoming)
        {
            //The call state, before connection is established, when a call is incoming but not yet answered by the user.
            NSLog(@"Incoming Call");
        }

        if(call.callState == CTCallStateConnected)
        {
            //The call state when the call is fully established for all parties involved.
            NSLog(@"Call Connected");
        }   

        if(call.callState == CTCallStateDisconnected)
        {
            [self release];
            NSLog(@"Call Ended");

        }

    };

Upvotes: 0

erotsppa
erotsppa

Reputation: 15021

This cannot be done. The flag idea is nice until you realize that not all calls termination returns you to the app. One example of this is if you hang up the call by press the top power button.

For those cases, the flag will be inconsistent (ie. upon next launch your app will think that this is returning from a call when in fact it was launched from the home screen).

So to summarize there is no way to detect a return from the phone all and I have asked Apple dev support about this.

Upvotes: 3

Alex Reynolds
Alex Reynolds

Reputation: 96927

Before having your application launch the phone call, read a BOOL flag in the application NSUserDefaults database that asks whether it should launch that call, e.g. callWasMade.

If callWasMade is set to a initial default of NO, then set the flag to YES, save the flag's value to NSUserDefaults and then trigger the phone call.

On the subsequent launch of your application, the value of callWasMade (YES) is read from NSUserDefaults and the call does not get triggered.

At that point, it should be safe to flip the flag's value back to NO to allow the next call.

Upvotes: 1

Related Questions