1

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.

taber
  • 3,166
  • 4
  • 46
  • 72

4 Answers4

6

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");

}
Mark Mckelvie
  • 343
  • 4
  • 13
  • Works great. I use float comparison with 'systemVersion' instead: ``if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 4.2)`` – William Denniss May 04 '11 at 06:00
0

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.

taber
  • 3,166
  • 4
  • 46
  • 72
  • The only issue now is, I haven't been able to successfully load an ad in the simulator (4.0 and 4.2)... getting this error in bannerView:didFailToReceiveAdWithError: 'Error Domain=ADErrorDomain Code=3 "The operation couldn’t be completed. Ad inventory unavailable"' – taber Nov 23 '10 at 03:55
  • Another note - this does actually work on the device... just not in the simulator. I think it may be a router or little snitch related issue. All set now! – taber Nov 23 '10 at 03:57
0

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

Andrew
  • 551
  • 1
  • 3
  • 2
  • thanks - i was originally setting the banner size in IB, which seems to also be fixed by removing & re-adding the iAd framework to the project. – taber Nov 27 '10 at 04:33
0

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.

benvolioT
  • 4,507
  • 2
  • 36
  • 30