为了AlertView
在两个iOS 8
版本和更低版本中显示,您可以使用以下代码:
if ([self isiOS8OrAbove]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
} else {
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];
[self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)isiOS8OrAbove {
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"8.0"
options: NSNumericSearch];
return (order == NSOrderedSame || order == NSOrderedDescending);
}