Created
February 12, 2014 09:07
-
-
Save chancyWu/8952193 to your computer and use it in GitHub Desktop.
iOS exit app friendly code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment