17

I am having problems with my universal app. I have set the Base SDK to iPhone 3.2 and set the target to 3.1.

I have moved the files that are using the UIPopoverController to their own files and they shouldn't be loaded when loading the app on the iPhone. Still, when I build my app I get the following error when I build and debug to my device:

dyld: Symbol not found: _OBJC_CLASS_$_UIPopoverController Referenced from: /var/mobile/Applications/B3B90643-92DC-4E5C-8B2F-83A42D6D57E0/citybikes.app/citybikes Expected in: /System/Library/Frameworks/UIKit.framework/UIKit in /var/mobile/Applications/B3B90643-92DC-4E5C-8B2F-83A42D6D57E0/citybikes.app/citybikes

I really hope someone can help me.

Best regards, Paul Peelen

2 Answers 2

27

Even if they're not loaded in runtime, those files are still processed in linking. The symbol _OBJC_CLASS_$_UIPopoverController is therefore added into your app as one of those requiring dynamic linking.

There are 2 workarounds,

  1. Replace all appearance of UIPopoverController in a message (e.g. [UIPopoverController alloc]) with NSClassFromString(@"UIPopoverController"), or
  2. Make UIKit weakly linked.
14
  • 7
    @Paul: To make a library weakly linked, select your target, open "Info", then change the type from Required to Weak.
    – kennytm
    Jun 9, 2010 at 12:16
  • 1
    are there any consequences for making uikit weakly linked? Jun 18, 2010 at 13:30
  • 3
    @Andy: Some link-time error may be hidden, and cause the app to crash at run-time.
    – kennytm
    Jun 18, 2010 at 15:13
  • 1
    great question and answer . .i am also facing the same issue. Which is the safest option of the two ? 1st or 2nd one ?
    – thndrkiss
    Feb 17, 2011 at 14:35
  • 1
    @thndrkiss No, it will still be approved. Thats the option I went with. May 23, 2011 at 12:37
5

I strongly recommend you not weakly link UIKit. As KennyTM and I mentioned in our comments, this may hide future linker issues and result in crashes. I'm also simply not comfortable with telling the linker that UIKit is optional when it plainly isn't. Big hack.

Instead, initialize and call UIPopoverController indirectly using NSClassFromString:

Class popover = NSClassFromString(@"UIPopoverController");
if (nil != popover)
{
    self.myPopover = [[popover alloc] initWithContentViewController:myContent];
}

If you still have linker errors, you may need to call UIPopoverController's messages using NSSelectorFromString:

Class popover = NSClassFromString(@"UIPopoverController");
if (nil != popover)
{
    SEL myInit = NSSelectorFromString(@"initWithContentViewController:");
    self.myPopover = [[popover alloc] performSelector:myInit withObject:myContent];
}

For portability, I recommend writing a proxy object to handle these implementation details.

1
  • 1
    This is the best approach. However, personally I like using if ([UIPopoverControll class] != nil) { ... } instead.
    – simonbs
    Dec 7, 2012 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.