在iOS 8之后,我可以继续使用UIActionSheet和U​​IAlertView吗?

我有使用UIActionSheetUIAlertView应用程序。
在iOS8中,苹果公司的文档和一些网站表示,它们在iOS8中被弃用。

UIActionSheet文档
重要提示:UIActionSheet在iOS 8中已弃用。(请注意,UIActionSheetDelegate也被弃用。)要在iOS 8及更高版本中创build和pipe理操作表,请使用带有UIAlertControllerStyleActionSheet的preferredStyle的UIAlertController。

但在Xcode 6中,部署目标8.0不会为使用UIActionSheetUIAlertView生成警告。
通常,Xcode会为已弃用的API生成警告。
为什么Xcode不为UIActionSheetUIAlertView产生警告?
这是否意味着苹果实际上并不赞成这些类?
如果他们实际上不赞成他们,Xcode不会产生警告是非常危险的。

在另一个苹果的文档“iOS 8.0新增function”中说:

新的UIAlertController类replaceUIActionSheetUIAlertView类作为在您的应用程序中显示警报的首选方式。

https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html

UIActionSheetUIAlertView未在上述URL文档的“ 弃用API”部分列出。
所以,这个文档意味着UIAlertController是可取的,但UIActionSheetUIAlertView在iOS 8中也是可用的。

我应该用新的UIAlertController类来replace我的应用程序中的UIActionSheetUIAlertView吗?
或者我可以继续使用UIActionSheetUIAlertView

是的你应该。 最好导致弃用,导致突然中断。

总是最好不要使用折旧的代码,这一切都加上了写得很好的代码。 所以是的,使用UIAlertController。

是的,你应该更换你的代码。

当我尝试在我的代码中使用一些类UIActionSheetUIAlertView的函数和委托方法不起作用。

我每次都遇到问题和奇怪的结果。

因此,您不应使用已弃用的API。

我相信这一点,我认为如果应用程序上传到App Store与不赞成的API,那么该应用程序可以被拒绝。

需要一段时间才能找出新的方法,所以你可能会发现这个代码有用。 我支持iOS的老版本,所以我使用条件来决定使用哪个版本。 此代码在我的应用程序委托中运行。 如果您正在视图控制器中运行它,请replace

 [self.window.rootViewController presentViewController:alert animated:true completion:nil]; 

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

#define在我的.pch中,但我把它放在这里,因为这是我在条件中使用的。

  #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) - (void)applicationWillEnterForeground:(UIApplication *)application { if (self.window.rootViewController) { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { [self displayUIAlertController]; } else { [self displayUIAlertView]; } } } - (void)displayUIAlertController { NSString *alertMessage = [NSString stringWithFormat:@"Do you want to resume playing %@ or start a new session?", GAME_NAME_TITLE]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Welcome Back" message:alertMessage preferredStyle:UIAlertControllerStyleAlert]; // You can add as many actions as you want UIAlertAction *startNewSession = [UIAlertAction actionWithTitle:@"Start New Session" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self startNewSession]; }]; UIAlertAction *doNothingAction = [UIAlertAction actionWithTitle:@"Resume" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // Do nothing }]; // Add actions to the controller so they will appear [alert addAction:doNothingAction]; [alert addAction:startNewSession]; // Finally present the action [self.window.rootViewController presentViewController:alert animated:true completion:nil]; } - (void)displayUIAlertView { NSString *messageWithTitle = [NSString stringWithFormat:@"Do you want to resume playing %@ or start a new session?", GAME_NAME_TITLE]; self.alertView = [[UIAlertView alloc] initWithTitle:@"Welcome Back" message:messageWithTitle delegate:self cancelButtonTitle:@"Resume" otherButtonTitles: @"Start New Session",nil]; [self.alertView show]; } #pragma mark - Alert on restart // buttonIndex 0 is cancel and the game continues // buttonIndex 1 is Start New Session and the old results are saved and new session started - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { [self startNewSession]; } } 

不推荐使用的代码通常意味着以前版本不支持标记版本和未来版本。 如果您正在构build遗留应用程序(或将支持以前版本的应用程序),则应使用UIActionSheet和U​​IAlertView,但是如果要更新iOS8 +的代码,则应使用UIAlertController。 好的是,你以前编写的代码不会受到影响,所以用户可以毫无问题地使用旧版本的应用程序。

应该可以继续在iOS8中使用UIAlertView和UIActionSheet,因为它们在iOS8而不是在iOS7中被弃用。 这就是说,我遇到了类似的问题=> UIAlertView自动换行iOS8? 。 所以看来我们可能需要比我们预期的更快地移动到UIAlertController。