Possible Duplicate:
Force iphone app to restart programmatically
How can I restart/reopen my iphone/iPad application programmatically
These icons normally cannot be removed by the traditional technique used to delete apps. Luckily there is a very simple solution to the problem. Just simply restart your iPhone and the ghost app will disappear.
This may just look like a funny bug on the surface, but it's actually intended … The reason Apple now lets you arrange multiple copies of the same app is because of iOS 15's new Focus features. With Focus, users can disable home screen pages depending on which focus mode they are in.
(Typically, there's no reason to quit an app; quitting it doesn't save battery power, for example.) To quit the app, open the App Switcher, swipe right to find the app, then swipe up on the app. To reopen the app, go to the Home Screen (or App Library), then tap the app.
Look through the various folders or use the Search bar to find the app you want to duplicate. Tap and hold on the app, then drag it to the left edge of the screen and drop it onto a Home Screen. Repeat this process as many times as you like to create as many duplicates as you need.
Note:
Although this has been down-voted I think it is a perfectly valid question for a new iOS developer to ask. There is a way to 'restart' your app from the user's perspective which is not technically restarting or exiting the iOS App. As pointed out by other answers an iOS App should never explicitly exit because this is not allowed on iOS.
My Answer:
If you want your app to go back to the state it was in at launch this is not 100% possible but I will explain a way to get most of the way there that should be sufficient for all valid purposes.
The first thing to do is to re-create your root view controller. I recommend doing this from a method in the app delegate like this:
- (void)resetAppToFirstController
{
self.window.rootViewController = [[MyMainViewController alloc] initWithNibName:nil bundle:nil];
}
In many cases this will be enough, but any app-state that you have should also be reset in this method. For example log out a user, reset any non-persistent state, and nullify (release) all objects that you can. This method can also be used to initially create your first view controller from application:didFinishLaunchingWithOptions
.
Framework classes and Singletons:
You will not be able to completely reset the state of any framework singletons or per-app instances, such as these:
[UIApplication sharedApplication];
[NSNotificationCenter defaultCenter];
[NSUserDefaults standardUserDefaults];
[UIScreen screens];
// etc...
That is probably fine as you shouldn't be storing any non-persistent state in these anyway (except NSNotificationCenter
, but all registered observers should have been removed when the objects were released). If you do want to initialise or reset any framework state you can do it in the same resetAppToFirstController
method. Anyway, there should be no need to re-create these, or the window
object.
If you have any of your own singletons, you can re-create these by storing them in a singleton-holder class (which is itself a real singleton). Conceptually, this is a simple singleton class with properties for each of your other singletons and a reset
method to nullify and release them all. Your other singletons should use this class (instead of a static or global variable) to store singleton instances. Be careful if you use any third party libraries as they may also employ singletons and you will need to ensure these also use your singleton-holder so that you can reset them as needed. I think this technique is good practice anyway, because in some cases (for example unit testing) you do want objects which are usually singletons to go away and reinitialise to a pristine state. However, you don't want to couple the singleton implementations with your singleton-holder, so a good way to implement this is by using an NSMutableDictionary
as an associated object on [UIApplication sharedApplication]
with the singleton class names as keys. However, I'm going off topic a bit as this is a more advanced technique beyond the scope of this question.
The above should be sufficient to 'reset' your application as far as the user is concerned. You can even show the splash screen again if you want as your first view controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With