Skip to content

Instantly share code, notes, and snippets.

@dombarnes
Created March 12, 2015 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dombarnes/13a80063623a8f258f45 to your computer and use it in GitHub Desktop.
Save dombarnes/13a80063623a8f258f45 to your computer and use it in GitHub Desktop.
iOS7/8 UIAlert
{
if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending)) {
// use UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure you want to do this on iOS7?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}
else {
// use UIAlertController
UIAlertController *discardController = [UIAlertController
alertControllerWithTitle:@"Alert Title"
message:@"This is your alert message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *discardAction = [UIAlertAction
actionWithTitle:@"Discard"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action)
{
NSLog(@"Discard action");
}];
[discardController addAction:cancelAction];
[discardController addAction:discardAction];
[self presentViewController:discardController animated:YES completion:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment