简体   繁体   中英

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. 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.

You simply have to check if the method you're trying to call really exists:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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