views:

48

answers:

1

According to the iOS Reference Library:

In iOS 4.0 and later, it is possible to mark individual resource files as usable only on a specific type of device.

Does this mean that if you're creating an Universal app for 3.X devices, and the 3.2 iPad in particular, you can't use device-specific resources with the ~ipad and ~iphone sufixes?

If so, is this the correct way to deal with device-specific resources?

UIImage* anImage;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    anImage = [UIImage imageNamed:@"MyImage-iPad.png"];
} else {
    anImage = [UIImage imageNamed:@"MyImage-iPhone.png"];
}  

Any additional considerations I should know of?

+2  A: 

Yes, you're right, that feature does not work on current iPads - iOS 3.2.

As a workaround I've created a category in UIImage, so I can use it like anImage = [UIImage mbImageNamed:@"MyImage.png"]. Category method simply puts "~iPad" before the suffix on iPad - code similar to yours.

Another ugly thing is that UIWindowControllers do not load xib files depending on device. I've created a base class for all my window-controllers and load the iPad specific XIB:

@implementation MBPadAwareWindowController
- (id)init
{
    NSString *className = NSStringFromClass([self class]);
    NSString *nibName = UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad ? className : [className stringByAppendingFormat:@"-iPad"];
    return [self initWithNibName:nibName bundle:nil];
}
@end
Michal