gpt4 book ai didi

iphone - 在 iOS 5 应用程序中有条件地支持 iOS 6 功能

转载 作者:可可西里 更新时间:2023-11-01 03:25:58 25 4
gpt4 key购买 nike

如何在 Minimal Deployment Target 设置为 iOS 5.0 的应用中支持 iOS6 的功能?

例如,如果用户使用的是 iOS 5,他将看到一个 UIActionSheet,如果用户使用的是 iOS 6,他将看到另一个适用于 iOS 6 的 UIActionSheet?你怎么做到这一点?我有 Xcode 4.5 并且想要在 iOS 5 上运行的应用程序。

最佳答案

您应该始终更喜欢检测可用的方法/功能,而不是 iOS 版本,然后假设方法可用。

参见 Apple documentation .

例如,在 iOS 5 中显示模态视图 Controller 我们会做这样的事情:

[self presentModalViewController:viewController animated:YES];

在 iOS 6 中,UIViewControllerpresentModalViewController:animated: 方法已弃用,您应该在 iOS 中使用 presentViewController:animated:completion: 6、但是你怎么知道什么时候用什么?

您可以检测 iOS 版本,并通过 if 语句指示您使用前者还是后者,但这很脆弱,您会犯错误,也许 future 更新的操作系统会有新的方法来执行此操作。

正确的处理方式是:

if([self respondsToSelector:@selector(presentViewController:animated:completion:)])
[self presentViewController:viewController animated:YES completion:^{/* done */}];
else
[self presentModalViewController:viewController animated:YES];

你甚至可以争辩说你应该更严格并做类似的事情:

if([self respondsToSelector:@selector(presentViewController:animated:completion:)])
[self presentViewController:viewController animated:YES completion:^{/* done */}];
else if([self respondsToSelector:@selector(presentViewController:animated:)])
[self presentModalViewController:viewController animated:YES];
else
NSLog(@"Oooops, what system is this !!! - should never see this !");

我不确定你的 UIActionSheet 示例,据我所知这在 iOS 5 和 6 上是一样的。也许你正在考虑 UIActivityViewController如果您使用的是 iOS 5,您可能希望回退到 UIActionSheet,因此您可能会检查一个类是否可用,请参阅 here怎么做。

关于iphone - 在 iOS 5 应用程序中有条件地支持 iOS 6 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com