0

I have two files .h and .m with some util methods to be called from viewcontrollers. I have one with an alertview, which when the ok button is clicked, the app would terminate.

I will use the next code to exit, after user click the button:

[[UIApplication sharedApplication] terminateWithSuccess];

I have a warning saying me that UIApplication shared doesn't have an interface.

My code:

    #pragma mark - SHOW ALERTVIEW FOR IOS 7 or less AND IOS 8
   +(void) showQuitAlert:(NSString*)alertTitle withMessage:(NSString *)alertMessage{

        NSString *alertOkButtonText = @"Accept";

      if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( NSFoundationVersionNumber_iOS_8_0 ) ) {
              NSLog(@"iOS 8 dialog process");
             id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;

          if([rootViewController isKindOfClass:[UINavigationController class]])
         {
            rootViewController = [((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
         }

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alertTitle
                                                                             message:alertMessage
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    //We add buttons to the alert controller by creating UIAlertActions:
    UIAlertAction *actionOk = [UIAlertAction actionWithTitle:alertOkButtonText
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action)
                               {
                                   [alertController dismissViewControllerAnimated:YES completion:nil];
                                   [[UIApplication sharedApplication] terminateWithSuccess];
                               }];


    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             [alert dismissViewControllerAnimated:YES completion:nil];

                         }];
    UIAlertAction* cancel = [UIAlertAction
                             actionWithTitle:@"Cancel"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [alert dismissViewControllerAnimated:YES completion:nil];

                             }];

    [alert addAction:ok];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];

    [alertController addAction:actionOk];
    [rootViewController presentViewController:alertController animated:YES completion:nil];
}

if (SYSTEM_VERSION_LESS_THAN(NSFoundationVersionNumber_iOS_7_0) ) {
    NSLog(@"iOS 7 or less dialog process");

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
                                                        message:alertMessage
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:alertOkButtonText, nil];
    [alertView show];
   }

}

Thanks

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94

1 Answers1

0

You are not supposed to provide "Exit app" functionality in iOS, like in Android. Users should tap Home button to get to the Home screen. As simple as that.

Yevgeniy Leychenko
  • 1,287
  • 11
  • 25
  • I have a functionality in my app that I want only some users with a specified attribute in their profile could access it. So, I have 2 options, or give the functionality or go out. Sorry if I don't explain me well. – Víctor Martín Jun 29 '15 at 14:33
  • Instead of going out you could just inform users that they are not allowed to do that. By means of alert view, for example. – Yevgeniy Leychenko Jul 02 '15 at 06:41