john ellis
john ellis

Reputation: 2164

terminating an app from didFinishLaunchingWithOptions

So, I have an app that monitors significant location changes. I want to only record changes at most every 2 hours. The other times, I really don't want my app to startup at all. Does anyone know if I can terminate my app from within

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Will returning "False" cause my app not to be loaded (from the docs it seems that is only if it is trying to handle a URL).

Upvotes: 0

Views: 718

Answers (3)

Geet
Geet

Reputation: 2437

you can try exit(0); but Let me warn you apple may reject your app if you terminate your app willingly, what would be better is to show a dialogue box containing the reason and asking the user to close the app on thier own.

Upvotes: 1

Jonathan J.
Jonathan J.

Reputation: 171

You really should not terminate your application, but should prompt the user that there's nothing to show at the moment and have them go to the home screen.

However, if you really want to, you can use abort().

From Apple's Developer Library (emphasis added):

In iOS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion. [...]

If during development or testing it is necessary to terminate your application, the abort function, or assert macro is recommended.

Upvotes: 0

codester
codester

Reputation: 37189

You should not terminate the app as it lead to rejection by apple.As docs say

There is no API provided for gracefully terminating an iOS application.

You can show pop up to user for appropriate message.During development or testing you can call abort().But you should not ship your app with any of terminate api as apple strongly discourage this.

Upvotes: 2

Related Questions