iAds "Invalid content size 'ADBannerContentSizePortrait' passed to ADAdSizeForBannerContentSize" in iOS 4.2
Update 12/16/2010: It looks like there is a similar issue when targeting 4.0 开发者_如何转开发devices with the 4.2 SDK... your app will crash immediately if you used Interface Builder to create your ad banner view. Weak-linking the iAd framework and Re-creating the ad banner implementation on the code side of things was the fix. Thanks to this thread by Ray Wenderlich: http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
---
Hi, I just tried to run my app using iOS 4.2 SDK (final) and targeting iOS 4.0 devices, and even though my app compiles fine, I get this error immediately upon running...
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Invalid content size 'ADBannerContentSizePortrait' passed to
ADAdSizeForBannerContentSize'
...
I tried...
- (void)viewDidLoad {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
}
... but no luck, still getting the same crash error. In IB it looks like the only options for "Sizes" are "Portrait, Landscape, or Both" which I guess iOS 4.0 is not a fan of.
Anyone have any suggestions? Thanks a lot.
This worked for me. It seems that the os versions below 4.2 still want the deprecated content size identifiers, at least when the ADBannerView is created in Interface Builder. I also have the iAd framework weak-linked as a precaution. I hope this is helpful to someone, and thanks so much to the great community on this site for all the wonderful information and insight!
// if the current version of the os is less than 4.2, use the old way of defining the banner size
if ([[[UIDevice currentDevice] systemVersion] compare:@"4.2" options:NSNumericSearch] == NSOrderedAscending) {
adBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
NSLog(@"below 4.2");
} else {
adBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
NSLog(@"4.2 or above");
}
you have to change
- (void)viewDidLoad {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
}
to
- (void)viewDidLoad {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait //or landscape
}
what you had was deprecated meaning its no longer supported as of iOS 4.2
It looks like if you remove the iAd framework and re-add it using "Add existing framework..." this fixes the issue... weird. Hope this helps someone else.
The answer that is found in the "update" of the question is correct. Note that at this time of this writing, the thread by Ray Wenderlich needs updating because it uses deprecated iAd constants. Otherwise it is a very good resource for solving this problem.
精彩评论