Question

I work on an universal app that uses UIPopoverController for the iPad version. (Both the base SDK and the deployment targets are iOS 4.3)

When I use the iPhone simulator (version 4.3) to test conditional code paths for iPad and iPhone neither the weak linking nor the NSClassFromString(@"UIPopoverController") approach give the expected behavior.

When testing weak linking of the UIKit framework I make sure to user the LLVM 2.1 compiler and make the UIKit framework 'Optional' in 'Target->Build Phases->Link Binary with Libraries'. (As I understand is the way to do it in Xcode 4.1).

Running the code

if ([UIPopoverController class]) { 
...
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
...
}

on the iPhone simulator crashes the application indicating that the [UIPopoverController class] does not return nil. Replacing [UIPopoverController class] with NSClassFromString(@"UIPopoverController") above, results in the same crash.

Does anyone know how to go about to make these conditional checks work when running on the simulator?

Was it helpful?

Solution

Try determining whether or not the code is running on an iPad.
If it does, you can safely use UIPopoverController.

- (BOOL)isPad
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)])
    {
        return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
    }
    else
    {
        return NO; // all iPad OS's implement -userInterfaceIdiom
    }
}

OTHER TIPS

UIPopoverController class exists as part of iOS starting version 3.2 so it should not return nil on any device with iOS version 4.x even iPhone, only iPhone with iOS 3.1.3 and below you get nil with weak(optional) linking. To determine wether you can use this class you try suggested above solution with userInterfaceIdiom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top