Iphone iOS 5应用程序中对iOS 6功能的有条件支持
如果Iphone iOS 5应用程序中对iOS 6功能的有条件支持,iphone,objective-c,ios,xcode,iphone-5,Iphone,Objective C,Ios,Xcode,Iphone 5,如果最小部署目标设置为iOS 5.0,您如何在应用程序中支持iOS 6的功能 例如,如果用户有iOS 5,他将看到一个UIActionSheet,如果用户有iOS 6,他将看到iOS 6的另一个UIActionSheet?你是怎么做到的? 我有Xcode 4.5,想要一个应用程序在iOS 5上运行。你应该总是更喜欢检测可用的方法/功能,而不是iOS版本,然后假设有可用的方法 看 例如,在iOS 5中,要显示模式视图控制器,我们将执行以下操作: [self presentModalViewCont
最小部署目标设置为iOS 5.0,您如何在应用程序中支持iOS 6的功能
例如,如果用户有iOS 5,他将看到一个UIActionSheet
,如果用户有iOS 6,他将看到iOS 6的另一个UIActionSheet
?你是怎么做到的?
我有Xcode 4.5,想要一个应用程序在iOS 5上运行。你应该总是更喜欢检测可用的方法/功能,而不是iOS版本,然后假设有可用的方法
看
例如,在iOS 5中,要显示模式视图控制器,我们将执行以下操作:
[self presentModalViewController:viewController animated:YES];
在iOS 6中,UIViewController
的presentModalViewController:animated:
方法已被弃用,您应该在iOS 6中使用presentViewController:animated:completion:
,但您如何知道何时使用什么
您可以检测iOS版本,并使用if语句指示您是否使用前者或后者,但是,这是脆弱的,您会犯错误,也许未来更新的操作系统将有一种新的方法来实现这一点
正确的处理方法是:
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和iOS 6上也是如此。可能您正在考虑使用UIActivityViewController
进行共享,如果您使用的是iOS 5,您可能希望退回到UIActionSheet
,因此您可能需要检查一个类是否可用,看看如何操作。您可以在项目设置中链接到该框架,在这种情况下,该框架可能不会出现在所有版本中,与您的情况一样,您只需将include设置为可选而不是必需。---问题被删除了。。。。问题/评论。@Daniel:如何知道使用respondsToSelector
?或者应该对每个方法调用执行此操作?响应选择器:
将检查您在接收器上传递给它的方法的可用性。因此,一般来说,您将在要调用的方法上调用它。有时,您将调用属于同一iOS版本/规范的多个方法,因此检查其中一个可以假定另一个可用。