2014-10-07 73 views
2

由于UIAlertController用于显示iOS8.my应用程序中的警报应与ios6,ios7兼容。我认为ios6,7仍在使用UIAlertView来显示警报。 我想通过不同的方式检查ios6,7,8后显示警报,例如使用UIAlertView的ios7和使用UIAlertController的ios8。我需要objectiv -c代码。使用iOS7,iOS8显示警报

请帮忙!!

在此先感谢!

+0

http://stackoverflow.com/questions/7848766/how-can-we-programmatically-detect-which-ios-version-is-device-running-在 – Signo 2014-10-07 07:04:16

回答

3

检查如果类是可用

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]; 

} 
+0

谢谢@jcesarmobile! – 2014-10-07 07:24:03