Weak linking on iPhone refuses to work

Posted by Jonathan Grynspan on Stack Overflow See other posts from Stack Overflow or by Jonathan Grynspan
Published on 2010-06-09T02:53:49Z Indexed on 2010/06/09 3:02 UTC
Read the original article Hit count: 469

Filed under:
|
|

I've got an iPhone app that's mainly targetting 3.0, but which takes advantage of newer APIs when they're available. Code goes something like this:

if (UIApplicationDidEnterBackgroundNotification != NULL)
    [nc addObserver: self selector: @selector(irrelelvantCallbackName:) name: UIApplicationDidEnterBackgroundNotification object: nil];

Now, according to everything Apple's ever said, if the relevant APIs are weakly linked, that will work fine because the dynamic linker will evaluate UIApplicationDidEnterBackgroundNotification to NULL. Except that it doesn't. The application compiles, but as soon as it hits "if (UIApplicationDidEnterBackgroundNotification != NULL)" it crashes with EXC_BAD_ACCESS.

Is this simply a matter of a compiler flag I need to set? Or am I going about this the wrong way?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c