1

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.

4

6 回答 6

7

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.

于 2012-12-31T06:01:39.763 回答
3

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.

于 2012-12-31T05:42:40.953 回答
3

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.

于 2012-12-31T05:51:58.627 回答
2

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!

于 2012-12-31T05:47:45.620 回答
0

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.

于 2012-12-31T06:30:08.383 回答
-1

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.

于 2012-12-31T06:45:18.493 回答