Is there any method that I could display a message before sending the app to the background by pressing the home button?
And the app should be stays in the foreground until the user responds to the message being displayed.
though you cant stop ur app from going to background, I have a thought...
you can schedule a UILocalNotificaiton
in applicationWillEnterBackground
and trigger it immediately. Your app will surely move to background but this way you can display ur message there and if user interacts with your message with "Action" button rather than "Cancel", your application will return back in active state.
just sharing my thought.. might be of ur help as I don't exactly know what's ur purpose behind such implementation.
Not possible. Once the home button is pressed you lose control of the app and there isn't really anything you can do about it.
You can't do this.
As you will press home button, then you will loose control of your app. And also apple will not allowed to do changes with basic device features.
Answer for your question is : No Way!
There is no Apple-supported method to terminate your application programmatically with an Alert.
When an iPhone user presses the Home button, he will be well aware that he needs to quit ! So "a message" make no sense there!
Try applicationWillResignActive
in ApplicationDelegate.m
, and use performSelector:@selector(showAlert:) waitUntilDone:YES.
I am not sure that will work, but you try with that. And, you may also want to assign the alert's delegate for action on some button press.
You can do this by your own logic. Add UIAlertView
in applicationWillEnterBackground
, and in response of UIAlertView
you can take action whether to go to background or stay in foreground.