2

As UIAlertController is used for showing alert in iOS8.my app should be compatible with ios6, ios7 too.I think ios6,7 are still using UIAlertView for showing alert. I want to show alert after checking for ios6,7,8 by different ways like for ios7 using UIAlertView and for ios8 using UIAlertController.I need objectiv-c code.

Please Help!!

Thanks in advance!!

Tanvi Jain
  • 917
  • 2
  • 7
  • 19
  • http://stackoverflow.com/questions/7848766/how-can-we-programmatically-detect-which-ios-version-is-device-running-on – LS_ Oct 07 '14 at 07:04

1 Answers1

3

Check if the class is available

if ([UIAlertController class]){
    // ios 8 or higher
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert title" message:@"Alert message" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:ok];

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

} else {
    // ios 7 or lower
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Alert title" message:@"Alert message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

    [alert show];

}
Mike S
  • 11,329
  • 6
  • 41
  • 76
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176