How to programmatically exit from an iPhone application? - iphone

I have an iPhone application which will exit on it's own after a user completes a particular action. I currently use exit(0) to leave the application and I have had no troubles with it until recently. I understand that this isn't the "right" way to exit an application but it is something that I want to do. The issue I am having is when the device awakes from hibernation, with my application as the active one, exit(0) is called and the application would restart after exiting.
This strikes me as quite odd and am wondering if this is a bug or am I doing something wrong? Is there a better way to gracefully exit an application without having the user hit the home key?
Thanks

Apple's way is to alert the user that the app is finished and they must click home to quit. You shouldn't do this in your code. If its obvious that your app is quiting to reviewers then it most likely won't get approved.

You can use this private command to quit your app with an animation (after you added the UIApplicationExistsOnSuspend key in your Info.plist) :
[[UIApplication sharedApplication] suspend];
But your app will be rejected if you want to put it in the App Store

There is a link here where may be have your answered: link text
But it doesn't exist public API to terminate programmatically your iphone application. (see Technical Q&A QA1561 from the iPhone Dev Center)

I see the same issue. I was able to stop this by calling exit(1) instead.

//#step invoke the normal routine applicationWillTerminate
if ([[UIApplication sharedApplication].delegate respondsToSelector:#selector(applicationWillTerminate:)])
{
[[UIApplication sharedApplication].delegate performSelector:#selector(applicationWillTerminate:) withObject:[UIApplication sharedApplication]];
}
//#step force quite app
kill(getpid(), SIGINT);
I think that is no private API was used ....

Related

Is it possible to quit iOS app after we do some checks

We don't want the user enter our app if the app is out-dated.
Is that is possible to quit a iOS app when we do some date check BEFORE the app launch?
Or it is possible to quit the application after the main view is loaded?
Before the app launches: no. The launch animation is already in progress when the OS calls main.
After some time (1-2 sec): yes. You can use one of
[[UIApplication sharedApplication] terminateWithSuccess];
exit(0);
abort();
assert(0);
pthread_kill(pthread_self());
so many ways, but neither will go through AppStpre - you're not supposed to close your app programmatically. You're supposed to notify the user via an UIAlertView about the outdated app and disable interaction with the app.
According to Apple you cannot exit(quit) your application through code. i.e if you use exit(0). Your application will be rejected for that. Although you can use exit(1) and delay the exit time of your application. Or you may like to use local notification which is quite handy.
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
Source

How to kill my app from multitasking using code in iphone?

I am looking for a way to kill my app (using code) with a UIbutton and do not keep it on multitasking.
I have tried :
- exit(0);
- applicationWillTerminate
but these 2 methods kill the app but don't stop it from multitasking.
There is no way to programmatically remove your application from the task bar, also please note that if you use any of the methods you wrote in your answer, your application will be rejected by apple
Omar's answer is right (so +1 for him for being faster than me, as usual). You're supposed to give the user the control of deciding when to kill your application and not kill the application yourself.
There is one way to quit the app that appears to work, which is to add the "UIApplicationExitsOnSuspend" key to your app's Info.plist file. When the user puts the app into the background (i.e. home button or incoming call), the app will quit. More information is available in this related question](http://stackoverflow.com/questions/3421400/quit-app-in-ios4). Hope this helps!

recognize that user call somebody

how to regognize that user call somebody from code?(means i have an app and want to do sth when user call somebody)
You can't do that I'm afraid, firstly your app won't be running when they are calling someone and secondly you can't access the phone functions from the SDK. Might be possible with a background process on a jail broken phone.
This is not possible, not through code nor through notifications. You can't do anything to stop this, when a phonecall comes in, your application gets suspended, like as if you'd press home in iOS 4 and it will multitask if it has been programed to do so. Have a look at the UIApplication implementations for multitasking and do your work there.

Disabling home button on iPhone/iPad

First of all, I'm completely aware that doing this will get my app rejected by Apple, that it's a poor user experience, and so on.
My question is fairly simple, is there a way using private APIs to disable the home button? The aim is to effectively put an iPad into kiosk mode.
You can't disable the menu button. This is handled by the SpringBoard which you cannot control unless the device is jailbroken.
You can relaunch the app immediately after the user quit, however. Assuming you have registered the kioskRelaunch112084 URL scheme:
-(void)applicationWillTerminate:(UIApplication *)application {
[application openURL:[NSURL URLWithString:#"kioskRelaunch112084://"]];
}
Note that the user can still force-quit the app.
It can be done really easily using a mobile config. See my answer here Lock-down iPhone/iPod/iPad so it can only run one app
If it's going to be in a kiosk of some sort, can you just put a metal plate over it, and mount the thing tightly enough so that it can't reasonably be pressed?
You might take a look under the hood of this app as a place to start.
Also, rather than a strip solely around the home button, try this.

How to find a call is unanswered in iphone

If i make a call from an application using
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://1234567890"]];
How can i check if the call is answered or unanswered
Thanks,
You cannot check this. When this URL is opened your application will be closed and phone app will be launched. Since you cannot access calls data from your app there is little you can do. This may be possible in jailbroken iPhone.
Pop up a dialog when the app re-opens asking the user if the call went through. You better have a good reason for wanting to know though or the user will be mighty annoyed!
Otherwise you are out of luck.
Not an iPhone app developer but is it possible to query the phone log the next time the app loads and check time on call or something and if it is over 20 seconds consider it completed or something like this?
There is no access to the iPhone phone from third party software. Luckily.
you can reffer
How can I check missed call in iPhone using Objective-C?