7

I am buliding a dark themed iOS 6 and 7 app. I understand I can call [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; to make the iOS 7 status bar suit a dark color theme application.

The problem is I am going to submit my app to the App Store and currently Xcode 5 is not ready for that, so I have to use Xcode 4.6.x to do this task. However with Xcode 4.6, I am not able to compile the new method from iOS 7. I think I have to do something like ""if ios7"" then do [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; and reposition my application window.

I am trying to do this with #ifdef ... #else... this code is [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; inside the viewDidLoad.

Could anyone help to understand how to use #ifdef... with the method in some functions.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
HYC
  • 69
  • 1
  • 1
  • 7

2 Answers2

22

While I'm not 100% sure I can fully answer this without breaching NDA, I'll do my best to point you in the right direction.

You need to use the __IPHONE_* #defines in Availability.h

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0 && defined(__IPHONE_6_0)
  // iOS 6+ code here
#else
  // Pre iOS 6 code here
#endif

Please be aware that #if and #ifdef will determine what code is compiled, it is not a runtime detection mechanism.

You can easily access Availability.h by using Open Quickly and typing in Availability.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Steve Wilford
  • 8,894
  • 5
  • 42
  • 66
  • There is nothing in your answer that is covered by an NDA. Why would you think that? Only iOS 7 specific APIs are covered. – rmaddy Aug 23 '13 at 15:44
  • Surely the contents of Availability.h as supplied in the iOS 7 SDK is covered under NDA? Regardless this answer should be able to be adapted for iOS 7 easily without even looking at the header file. I +1'd and up-voted your other answer though :) – Steve Wilford Aug 23 '13 at 15:48
  • `iOS17` -- #if __IPHONE_OS_VERSION_MAX_ALLOWED >=__IPHONE_17_0 && defined(__IPHONE_17_0) ✌ – dklt Jul 18 '23 at 05:22
2

take a look to respondsToSelector

 [delegate respondsToSelector:@selector(myMethod:)]
p1ckl3
  • 177
  • 1
  • 4
  • 3
    This doesn't help. The compiler will still complain on the line that actually calls the method. – rmaddy Aug 23 '13 at 16:07
  • Not if the receiver is of type `id` or you use `performSelector:withObject:`. Anyway, the `#if` method above is probably tidier. – jbg Jul 13 '14 at 00:13