Search code examples
iosafnetworking-2

Use of __IPHONE_OS_VERSION_MIN_REQUIRED without comparison


In AFNetworking 2.0, NSHTTPSessionManager.h has the following code:

#if __IPHONE_OS_VERSION_MIN_REQUIRED
#import <MobileCoreServices/MobileCoreServices.h>
#else
#import <CoreServices/CoreServices.h>
#endif

__IPHONE_OS_VERSION_MIN_REQUIRED is used without specifying a version to compare to. Why? Is it because this macro is defined when Core Services framework is changed to MobileCoreServices.h?


Solution

  • This is a check if the device is an iOS device or an OS X one. MobileCoreServices is used on iOS while CoreServices is used on OS X.

    __IPHONE_OS_VERSION_MIN_REQUIRED is only defined on iOS, which is why this works. The other check is MAC_OS_X_VERSION_MIN_REQUIRED, which is only defined on OS X and can therefore be used in the reverse fashion.

    This is a bad check, and shouldn't be done. One should create separate frameworks for each platform. I guess they did this because it might save some hard disk space, as the rest of the framework is probably nearly identical.