简体   繁体   English

如何在XCode中为不同版本的iPhone OS进行编码?

[英]How do I code for different versions of iPhone OS in XCode?

I seem to have a bug because I'm using -[AVAudioSession setActive:withFlags:error:] in an iPhone project that is for 3.0 - 4.0.2. 我似乎有一个错误,因为我在用于-[AVAudioSession setActive:withFlags:error:]的iPhone项目中使用-[AVAudioSession setActive:withFlags:error:] So I guess I need to put one of those #IF lines in, so I can get it to do different things based on the OS version... But I can't find out how to do it. 因此,我想我需要插入其中的#IF行之一,以便可以根据操作系统版本执行不同的操作……但是我不知道该怎么做。

You simply have to check if the method you're trying to call really exists: 您只需要检查您尝试调用的方法是否确实存在:

if ([AVAudioSession respondsToSelector:@selector(setActive:withFlags:error:)]) {
   // call it
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM