tags:

views:

40

answers:

1

How can you check if a constant is set at runtime? For instance, in iOS 4, UIApplicationDidEnterBackgroundNotification is available, but when running on iOS 3 it will through an error if you try to use it.

+1  A: 

You should probably look at this other question, which in my opinion also answers yours. if (&UIApplicationWillEnterForegroundNotification != NULL) should be dynamic-linking-safe and tell you whether the constant exists or not.

Romain
If you are using LLVM, you have to do some tricks to get it to not optomize out your if statement. This works for me.BOOL backgroundOK = if (backgroundOK) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification bject:nil];}
David Beck