How to show exit confirm dialog when user clicks Home button? - iphone

I need to show the exit confirm dialog when user pressing the Home button. If yes, need to exit the application.
Is it possible to show when pressing the Home button?

This would probably cause your app to be rejected
From the Apple HIG:
Always Be Prepared to Stop
iOS apps stop when people press the Home button to open a different app or use a device feature, such as the phone. In particular, people don’t tap an app close button or select Quit from a menu. To provide a good stopping experience, an iOS app should:
Save user data as soon as possible and as often as reasonable because an exit or terminate notification can arrive at any time.
Save the current state when stopping, at the finest level of detail possible so that people don’t lose their context when they start the app again. For example, if your app displays scrolling data, save the current scroll position. To learn more about efficient ways to preserve and restore your app’s state, see “State Preservation and Restoration”.

I'm not sure you can stop the app from terminating or going into the background. You can tell it is about to go background through the app delegate applicationWilResignActive or be terminated by applicationWillTerminate.

Related

iOS app - on quit ask for password

I am building iOS app for promo. The client asked that people using it should never quit it, so I got an idea.
When people are trying to quit, they would be asked to enter the password, otherwise it's impossible. Is there a solution to this?
I would appreciate any help, thanks!
Here are the steps to easily disable the home button :
Launch the Settings app from the Home screen of your iPhone or iPad Tap on General.
Scroll down towards the bottom of the screen and tap on
Accessibility.
Under the Learning section, tap on Guided Access.
If it's not already, turn the toggle next to Guided Access to the On
position, then choose a passcode.
After having deployed your application on the device, open it and triple tap the home button.
Set your options and then tap on start.
You can leave the guided access mode by triple tapping the home button again, it will ask you for the passcode you set before.
Here is a link for more details (and illustrated with photos)
What you are doing is not possible I guess. See for quitting any app the user can simply press the big quit button on the ipad or iphone and then the app would go into the background nevertheless.
You can't prevent the user from quitting. If you try to prevent it, the OS will terminate the app directly. With iOS 4.0, you can have tasks that are allowed to complete in the background.
Check this out.
For an overview about running tasks.

How to do a clean app restart (iOS 6.1)?

I realized an app for iOS. It all goes well, works like a charm... until the device is restarted! When I manually close the app (for example, on my iPad I slide four fingers upwards, visualize the menu showing the app "alive", hold the icon of the app and press the red badge, terminating the app) and I try to open it again this is what happens to me:
First the app remains stuck on the last page visited before closing the app (I cannot tap buttons on the tab bar or do anything else)
Then, the only thing I can do is tap the Home button and try to open the app again
At this point all I get is a perfectly black screen
The restart seems to be not a real restart, or not to be clean. This is totally meaningless to me. Am I missing something?
EDIT :
Remove your application by press Hold down Application iCon From simulator/device
And then re-install app. and check it worked or not ???
If your view display with black screen then give it backGround Color redColor or as u wish.
Its iOS app natural behavior only.
When you press Home button on device, While running any iOS app it goes in background but the The app is still in background and its save application's state.
So if you Tap agin app's icon you will get the last screen where did you leave it.
Now, if you want to Restart the app from initial you need to clear it.
Go this way.
Just double press device's Home button you can see running apps on bottom like this
For delete particular app, you simply press and hold, you can see red (-) icon on app
just click on that and you are on way.
Now press Home button and Go to Start app!!
The problem is that Xcode, when it runs an app, attach to it a debbuger which prevents it to close normally and causes problems in the reopening. Thank you very much to this guy who pointed out the problem: https://stackoverflow.com/a/15176137/1272105

Launch image re-appear after hitting the "Home" button and reopening the app several consecutive times

If I press the home button and then re-launch the app, after around 10 times, the application showing splash screen and stuck for a few seconds or even crash.
There's a reason that could happen?
(The app is configured to background)
I found the problem.
I use mbprogresshud's third-party code.
And I found a mistake, this code include registration to UIApplicationBecomeActiveNotification
and this registration happens again whenever this notification recieved.
so, Caused stack over flow after several time that application move to the background and reopen.
Thanks about your answers.

Removing Application from Multitask Bar

As My application supports background task I have an Exit button which will call exit(0). My application gets closed properly but still an instance of the App is on Multitask Bar, i.e. bar when Home key is pressed twice.
Is there is any way to remove the App from Bar using code?
Open for any suggestion.
You are not allowed to exit your application programatically, it is against the guidelines and if you do this your app will almost certainly be rejected by Apple's software review team.
The only way an app can ever be closed is by the user pressing the home button. You can't have your own button for that.
You can have a button to stop your app from doing anything in the background of course.

UILocalNotification in sleep mode on iPhone

I'm developing a Voip application.
When I press the lock button(app goes to sleep), and the server sends a request I present a local notification.
The local notification is presented as it should and The button slider text says "slide to answer". If I slide here, the app gets open.
However, if now I press again the lock button, and then unlock, the notification is still presented and the slider text has changed to "slide to unlock".
Now, when I slide to unlock, it's as if I pressed the "close" button on a regular notification bar, meaning the app won't open.
My question is why on the second time the local notification is still presented ? and if so, is there a way to track the unlock button event or the unlock slider so I can tell the server that I don't want to answer the call ?
Thanks
The notification is only a dialog (i.e., the user can interact with it directly) for a short time - until the device is locked again, either by using the button or automatically after a time-out of about 15 seconds.
After that, it turns into a notification. The user cannot interact with it directly, apart from reading the message.
Sorry, but it doesn't get any better unfortunately.