1

I have a class that is using NSURLSession and I still need to support iOS 6. When I try to compile targeting iOS 6, it fails, since NSURLSession doesn't exist.

How do i disable this class from compiling for iOS 6?

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Tony
  • 656
  • 8
  • 20
  • Hmm, maybe you could check current version and split your code accordingly... Like here http://stackoverflow.com/questions/7848766/how-can-we-programmatically-detect-which-ios-version-is-device-running-on – Yanchi Oct 01 '13 at 18:22
  • i can use the check `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000` which will only compile on IOS7, but its not very pretty since it needs to be over the whole file – Tony Oct 01 '13 at 18:33
  • Yanchi's suggestion is good for when you don't want an application to crash due to unrecognized selectors, etc, when running on a device. If you just want to ignore a file so that Xcode 4 will allow you to compile the rest, remove it from the target, as specified here: http://stackoverflow.com/questions/2561715/xcode-is-there-a-location-flag-to-prevent-a-class-from-compiling – Kamaros Oct 01 '13 at 18:35
  • The issue is targeting iOS 6, not the XCode version. – Gabriele Petronella Oct 01 '13 at 18:37
  • If you create a second target for iOS 6, and remove your incompatible classes from it, you should be able to choose between building for an iOS 6 target and an iOS 7 target. – Kamaros Oct 01 '13 at 18:46

1 Answers1

1

If you need to support both iOS 7 and iOS 6.x then your base sdk should be iOS7 and iOS Deployment target should be iOS 6.0.

You should be modifying your class so that your application supports both iOS 7 and iOS 6.x

if ([NSURLSession class]) {
    // Use NSURLSession
}
else {
    // Start background task, iOS 6 way
}
rakmoh
  • 2,953
  • 1
  • 16
  • 14