Proper way to exit iPhone application?

前端 未结 25 3015
难免孤独
难免孤独 2020-11-22 01:54

I am programming an iPhone app, and I need to force it to exit due to certain user actions. After cleaning up memory the app allocated, what\'s the appropriate method to ca

25条回答
  •  孤城傲影
    2020-11-22 02:47

    - (IBAction)logOutButton:(id)sender
    {
       //show confirmation message to user
       CustomAlert* alert = [[CustomAlert alloc] initWithTitle:@"Confirmation" message:@"Do you want  to exit?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
       alert.style = AlertStyleWhite;
       [alert setFontName:@"Helvetica" fontColor:[UIColor blackColor] fontShadowColor:[UIColor clearColor]];
       [alert show];
    }
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    
       if (buttonIndex != 0)  // 0 == the cancel button
       {
          //home button press programmatically
          UIApplication *app = [UIApplication sharedApplication];
          [app performSelector:@selector(suspend)];
          //wait 2 seconds while app is going background
          [NSThread sleepForTimeInterval:2.0];
          //exit app when app is in background
          NSLog(@"exit(0)");
          exit(0);
      }
    }
    

提交回复
热议问题