开发者

Problems with iAd changes in 4.2

开发者 https://www.devze.com 2023-01-31 23:50 出处:网络
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:

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 hav开发者_如何学Pythone to use 4.2 as the deployment target?


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];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消