In iOS 4.2, there is a change in the references to the ADBannerView size. We used to use:
ADBannerContentSizeIdentifier320x50 & ADBannerContentSizeIdentifier480x32
But now we need to use:
ADBannerContentSizeIdentifierPortrait & ADBannerContentSizeIdentifierLandscape
This allows iOS 4.2 to resize the iAd based on the device / window size.
So how do you create a universal app that uses iAd's AND will run on iOS 4.0? Here's what I did (based on some help from Rincewind on the Dev forums; I didn't know how to check for an NSString. Now I do! You use &<string> and if that doesn't equal nil, you are good to go).
Overview: I chose to create two new string values and then based on whether or not the app was running on iOS 4.2, set them to the appropriate identifier.
In .h file (view controller)
{
NSString *PortraitBanner;
NSString *LandscapeBanner;
}
@property(nonatomic, retain) NSString *PortraitBanner;
@property(nonatomic, retain) NSString *LandscapeBanner;
@end
In .m file
@synthesize PortraitBanner;
@synthesize LandscapeBanner;
in my createBannerView method:
//If true then we're on iOS 4.2 (or newer) and we can use the identifiers
//If not true then we use the old identifiers
if (&ADBannerContentSizeIdentifierPortrait != nil) {
PortraitBanner = ADBannerContentSizeIdentifierPortrait;
LandscapeBanner = ADBannerContentSizeIdentifierLandscape;
NSLog(@"Running on iOS 4.2 or newer.");
} else {
PortraitBanner = ADBannerContentSizeIdentifier320x50;
LandscapeBanner = ADBannerContentSizeIdentifier480x32;
NSLog(@"Running on Pre-iOS 4.2.");
}
//Don't forget to release
in dealloc:
[PortraitBanner release];
[LandscapeBanner release];
Note: If you haven't checked out the Apple sample code iAd Suite, that's where my createBannerView method came from.
Then pretty much wherever you'd use one of the "ADBannerContentSizeIdentifier*" strings, use either PortraitBanner or LandscapeBanner. I've tested my app on iOS 4.1 and iOS 4.2 on several devices and my iPad and it is working fine.