2014-10-07 37 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