views:

68

answers:

1

Hi!,

I use macros to differ the versions but I can't force it to work properly. I used:

#ifdef _IPHONE_4_0
  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
 #else
  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
 #endif

and

#if __IPHONE_OS_VERSION_MAX_ALLOWED < _IPHONE_4_0
  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
 #else
  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
 #endif

and

#if defined(__IPHONE_4_0)
  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
 #else
  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
 #endif

No matter what version I use - always called only one of the lines. And the __IPHONE_4_0 is always defined. Any ideas?

Best Regards, Dmitry M.

+2  A: 

The #if… processor directives are resolved at compile time. As long as you compile for the 4.0 SDK, the 4.0 variant will always be chosen.

If you intend to make the app works for < 4.0, you should use a runtime check:

UIApplication* app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(setStatusBarHidden:withAnimation:)])
  [app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
else
  [app setStatusBarHidden:YES animated:YES];
KennyTM
thanks for answer. but in this case what for these macros can be used at all? I thought that the __IPHONE_OS_VERSION_MAX_ALLOWED will be different for the same app ruining on different OS. no?
Dmitry
God no. Macros only affect the state of the *compiler* -- once the app is compiled, they've disappeared into the mists of RAM and have no further effect upon the application. In this case, Apple uses them to distinguish between compilation targets so that one header file can be used for multiple targets and emit useful errors and warnings, among other things.
Jonathan Grynspan