Question

I'm aborting my iOS Application by below methods

-(void)cancelSelected
{
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure you want to exit?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];

    [alert show];

    alert = nil;
}

Method 1 :

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex)
        abort();
}

Method 2 :

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex)
        [NSException raise:@"Disagree terms and conditions." format:@"Quit, Cancel"];
}

Shall I do this to quit my iOS Application programmatically?

Will this abort() method leads to reject my app?

Thanks!

Était-ce utile?

La solution

See QA1561:

Q: 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.

Autres conseils

Yes the codes above will result in a reject. Use this code instead in your OK button of alert:

UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)

Yes, generally you will get rejected for that.

Just present an alert to the user with a singe option, so they must approve to dismiss the alert. Then, if they dismiss (approve) they can use the app and if they don't they can't and must quit the app manually.

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Game Over" message:@"Your time is up" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *close = [UIAlertAction actionWithTitle:@"close" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                                 **exit(0);**
                                                             }];
UIAlertAction *playagain = [UIAlertAction actionWithTitle:@"Play again" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                                  [self viewDidLoad];
                                                             }];

[alert addAction:close];
[alert addAction:playagain];

[self presentViewController:alert animated:YES completion:nil];

Use exit(0) for close current application

You can use below code to Quit iOS Application Programmatically with UIAlertView :-

Step 1:

Delegate "UIAlertViewDelegate" to your viewcontroller.h

for example:
 @interface User_mail_List : UIViewController< UIAlertViewDelegate >

Step 2:

//create your UIAlertView
UIAlertView  *exit_alertView= [[UIAlertView alloc] initWithTitle:@"Bizbilla !" message:@"\nAre you sure you want to Exit ?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
[exit_alertView show];

Step 3:

-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{
if(alertView==exit_alertView){//exit Alert Fns Start,,,,,
    if(buttonIndex==1){
        exit(0);
    }
}//exit Alert Fns End,,,,,

}

thanks,

On your alertview button click

You can use: exit(0)?

Or,

[[NSThread mainThread] exit], using this you can quit ios app.

How about calling fatalError() function? I've just used it, everything works as expected. (Hope this will not cause a rejection though.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top