Quit the iOS application if you can not download the database


This question already has an answer here:

  • Proper way to exit iPhone application? 22 answers

I want to quit the application if it is not able to download the database from the server. I try to download the database using NSURLSession. if it doesn't then show the alert view.

when user clicks on ok button in the alert, then i want to quit the application. As there is no database, it will crash to proceed. To avoid the crash i want to quit from the app programatically.

I want to achieve something like android's finish().

I have one util.h and util.m which does all download show alert box job. It extends NSObject. It is just like an utility not a controller.


#import <Foundation/Foundation.h>

@interface Util : NSObject {

NSURLSession *session;
//NSDictionary *plistDictionary;
NSURLSessionTask *task1;
NSURLSessionTask *task2;
NSURLSessionTask *task3;
UIAlertView *alertViewSpin;
NSMutableData *receivedData;


I have seen in one of the SO post..

 [self dismissViewControllerAnimated:YES completion:nil];
 [self.navigationController popViewControllerAnimated: YES];

But did not help. How can I do this?

How do I programmatically quit my iOS application?

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

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.

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.

Note that using exit(0) or [[NSThread mainThread] exit] may cause your app to be refused in the App-store submission

More information