0

I have a problem. I develop a application, this app run successfully on iOS 4.2. Now I would like to run it on iOS 3.2, but the application crash before it load. Because of this line of code:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:UIApplicationWillEnterForegroundNotification object:nil];

I understand that UIApplicationWillEnterForegroundNotification is not available for iOS 3.2. But when I use:

#ifdef __IPHONE_4_0
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDataAfterEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
#endif

The application still run in that line of code and cause crash again. I don't know what should I do to let 3.2 does not run that line of code.

Thank you very much

haisergeant
  • 1,111
  • 2
  • 13
  • 32
  • your #ifdef is evaluated at compile time not runtime. If you link your app against ios 4.2 sdk the condition is fulfilled. – Kai Mar 04 '11 at 09:26

2 Answers2

1

Check out this post. Probably better to do it like this or something similar.

How to detect current iOS is 4.1 or 4.2?

Community
  • 1
  • 1
Jamie
  • 5,090
  • 28
  • 26
  • Thank you. But I can not use NSClassFromString because this is the notification: UIApplicationWillEnterForegroundNotification is only available for iOS 4 and later. – haisergeant Mar 04 '11 at 04:56
1

use this

// #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000

  NSLog( @"After Version 4.0" ); 
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDataAfterEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];

// #else

// #endif

Ishu
  • 12,797
  • 5
  • 35
  • 51