In this block of code:
NSArray *supportedOrientations = nil;
if( iPhone ) { // bool
supportedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
// one array element
}
else if( iPad ) { // bool
supportedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations~ipad"];
// returns nil
}
else {
NSLog(@"%@:%@ device type not identified", kClassName, kMethodName);
}
If the device is iPhone, supportedOrientations has the array.
If it’s iPad, supportedOrientations is nil.
The file is always found, so the NSLog never displays (confirmed by stepping through with the debugger).
When checking the plist with text edit, I see:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Any ideas on why this is happening?
Running in iOS simulators version 4.3.
When a bundle loads its
infoDictionary, it examines each key in the dictionary. If the key is device-specific, the bundle checks whether the key refers to the current device.If the key refers to the current device, the bundle removes the device-specific part of the key. For example, on an iPad, the bundle changes
UISupportedInterfaceOrientations~iPadtoUISupportedInterfaceOrientations.If the key refers to a different device, the bundle removes the key from the dictionary. For example, on an iPhone, the bundle removes the
UISupportedInterfaceOrientations~iPadkey from the dictionary.So you can just do this:
That will do the right thing on all devices.
You can do this instead and it’s a little shorter: