views:

219

answers:

2

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.

+1  A: 

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.

Alex Reynolds
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
+2  A: 

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
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