-1

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
user3573587
  • 21
  • 1
  • 3
  • 2
    Why? There should be absolutely no need to do that. – luk2302 Aug 27 '17 at 08:23
  • I need it in my code. – user3573587 Aug 27 '17 at 08:31
  • No, you need to program the app in way it does not need a manual restart. – luk2302 Aug 27 '17 at 08:33
  • Just because the app is listed in the recent applications list doesn't mean it is running, but as others pointed out, calling `exit` is against apple's guidelines. – Paulw11 Aug 27 '17 at 08:36
  • Okay then what are the alternatives to reload the app when the user open it again ? I want ViewDidLoad to be executed again – user3573587 Aug 27 '17 at 08:50
  • 1
    no, you do not, there is no reason for that, put any custom logic you have in viewDidLoad into some other function and call that function. – luk2302 Aug 27 '17 at 09:14
  • So what if it's against Apple guidelines? The question is not whether it is, or it is not. There are some legitimate uses for that, especially for internal and testing purposes. – raven_raven Aug 31 '21 at 11:46

1 Answers1

1

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

Community
  • 1
  • 1
Ashutosh Dave
  • 382
  • 16
  • 33
  • Okay then what are the alternatives to reload the app when the user open it again ? I want ViewDidLoad to be executed again – user3573587 Aug 27 '17 at 08:50
  • 1
    put your portion of code into separate method which needed to be re-executed. call that function from viewDidLoad and also call from the code where you wanted to quit your application. – Ratul Sharker Aug 27 '17 at 09:23