This question already has an answer here:
iOS: Making an App terminate when leave screen
(1 answer)
Closed 7 years ago.
I have a simple game, made using the storyboard.
Obviously, when the user exits the application, it closes and stays in the background (no forced quit or closed).
Is there anything you can do, either in Xcode project settings or programmatically, that will close the app upon exiting, so when the user clicks the app icon, it runs from the start as normal? Just as if it had been manually closed?
Yes there is a way, but NO, you shouldn't do that. Apple will reject your application when you submit it, if you try to exit the app programatically. IOS apps should work the way apple recommends it to work.
From their official site:
Warning: Do not call the exit function. Applications calling exit will
appear to the user to have crashed, rather than performing a graceful
termination and animating back to the Home screen.
EDIT
Just for satisfying your curiosity, you can call exit(0); to close your app programatically.
Related
I have an app when a specific action fires I close the app and ask the user to reopen it again.
The problem is when the app executes exit(0) the app stays in the apps stack (when I click the home button twice). I want it to be killed completely so that viewDidLoad() will be executed again when the app opens.
You cannot terminate an app on it's own.
From Apple's Human User Guidelines...
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.
Have a look at this answer: https://stackoverflow.com/a/8491688/742298
This question already has answers here:
How to detect when user clears your app's notification
(2 answers)
Closed 6 years ago.
I have an app that will show a notification icon when the user has not been to the app in awhile I can get it to clear when I launch the app but I want it to clear when they swipe clear from their phone notifications. The code I use to clear when I open the app is
UIApplication.shared.applicationIconBadgeNumber = 0
I just started using swift today to help a coworker on their project. If anyone could point me in right direction at least would be appreciated.
Sorry but you can't "launch code" from your application if your app is not opened. Maybe you could use a shortcut with 3D Touch "Clear" or something more user friendly that would clear the notification badge without launching the app.
You can take a look at the officiel documentation here .
I am a newbee in iOS app development, and trying to create a small app using Xcode. One of my views has button to close the app. When a user taps this button, then I have to redirect the user to the "launch screen".
But don't know how. Can anybody guide me?
Thanks
First of all there is no way you can 'close' an app programmatically. The alternative solution is to force crash the app using the exit function.
you can use the code below:
exit(0);
Apple strongly discourages you to programmatically quit an iOS application. The standard way to move back to (redirect to) the Launcher screen (which by the way is Home screen for iOS) is when the user presses the Home button.
Calling exit(0), will not invoke the UIApplicationDelegate methods such as applicationWillTerminate: etc., and thus should not be used in general.
Reference of the Same can be found in Apple's Technical Q&A QA1561
I have an iOS application written in swift that leads the user through a series of questions. After the questions are finished, the app is done at this point. Later on an alarm will go off triggering the app to activate again. The issue is that I'm not sure how to exit the application once the questions are complete. I need to trigger the app to exit and go to the background. I've been fiddling around with an unwind segue but that doesn't go all the way back to exiting the app from what I've seen.
Can anybody give me a push in the right direction?
You can only exit the app using a private API. You really shouldn't force a user out of your app.
I my testing, when I exit (by pressing the home button) my app, it still is "running" in the background, thanks to the multitasking feature. However, I would like it to quit when the home button is pressed. Is this only happening to me?
Anyway, I have tracked it down to the applicationWillResignActive and the applicationDidBecomeActive methods in the app delegate. These get called for multitasking, but when I want to terminate, the app "resigns active." Any guidance on this issue is greatly appreciated!
Your application can opt out of multitasking (see the appropriate section in the iPhone Application Programming Guide) by adding the UIApplicationExitsOnSuspend key to your Info.plist and setting its value to YES.
In practice, Apple strongly recommends you not do this unless you have a very good reason for this behavior.
I think it's more efficient to suspend an app, when pressing the "Home" button. There's overhead in constantly launching and terminating apps. It's worse for the iOS operating system, and it's worse for user experience - because they need to wait for the app to launch again. Not sure what benefits you gain from terminating an app. If it's for simulation testing, my advice is to avoid that functionality, because your testing environment should be as realistic as possible. If your purpose is to clear cache or to make updates - that can all be done programmatically from subroutines.
Exiting subroutines
applicationWillResignActive
applicationDidEnterBackground
applicationWillTerminate
Entering subroutines
applicationDidBecomeActive
applicationWillEnterForeground
applicatonDidFinishLaunching
If you still insist on terminating an app when the user presses the "Home" button, despite the costs mentioned above - then set the UIApplicationExitsOnSuspend to true in your Info.plist as suggested by Brad Larson.
I wouldn't recommend trying to control the user's HOME button... deciding for them "exit" or "suspend".
I WOULD like to have HOME do an instant EXIT in the iPhone simulator... but haven't found any way to do that.