Question

I'm trying to use iAds in my app but I want to support all versions from 4.0 upwards. However the code for setting the current size identifier has changed in the 4.2 sdk, it used to be:

ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;

but in 4.2 the code is:

ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;

and therefore when if I use the old code in the 4.2 sdk it crashes and if I use the correct code for 4.2 any device running a previous version to 4.2 crashes. Does anyone know how I can support both or will I have to use 4.2 as the deployment target?

Was it helpful?

Solution

There is a workaround to support both 4.2 and earliers versions.

You could check if the constant exists at your ios version using something similar to the code bellow:

NSString *sizeIdentifier = &ADBannerContentSizeIdentifierLandscape != nil ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32;

and then just use the string to initialize you iAd view

[yourAdBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObject:sizeIdentifier]];

[yourAdBannerView setCurrentContentSizeIdentifier:sizeIdentifier];

OTHER TIPS

There's some other problem in your code — use of ADBannerContentSizeIdentifier480x32 under 4.2 does not cause a crash, indeed it doesn't even trigger a compiler warning. It's deprecated but remains available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top