3

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.

Lauri Larjo
  • 314
  • 1
  • 8

3 Answers3

3

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.

erotsppa
  • 14,248
  • 33
  • 123
  • 181
  • Yes, I also realized that the flag can get inconsistent. But it's a rare situation, and will fix itself automatically if the user just quits the app and then opens it again. I'll just go with this. – Lauri Larjo Jun 03 '09 at 10:48
1

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.

Community
  • 1
  • 1
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • Thanks! I already had a hasCalled-boolean, but apparently that wasn't saved anywhere so it didn't work. NSUserDefaults database was the answer to my problem. – Lauri Larjo May 26 '09 at 11:51
0

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");

        }

    };
Community
  • 1
  • 1
Bushra Shahid
  • 3,579
  • 1
  • 27
  • 37