4.2 中 iAd 更改的问题

发布于 2024-10-08 11:42:13 字数 411 浏览 0 评论 0原文

我正在尝试在我的应用程序中使用 iAds,但我想支持 4.0 及以上的所有版本。但是,用于设置当前大小标识符的代码在 4.2 sdk 中已更改,它曾经是:

ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;

但在 4.2 中,代码是:

ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;

因此,当我在 4.2 sdk 中使用旧代码时,它会崩溃,并且如果我使用正确的代码对于 4.2,任何运行 4.2 之前版本的设备都会崩溃。有谁知道我如何支持两者,或者我必须使用 4.2 作为部署目标?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彻夜缠绵 2024-10-15 11:42:13

有一个解决方法可以同时支持 4.2 和更早版本。

您可以使用类似于下面的代码的方式检查您的 ios 版本中是否存在该常量:

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

然后只需使用该字符串来初始化您的 iAd 视图

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

[yourAdBannerView setCurrentContentSizeIdentifier:sizeIdentifier];

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];
奶气 2024-10-15 11:42:13

您的代码中还有其他一些问题 - 在 4.2 下使用 ADBannerContentSizeIdentifier480x32 不会导致崩溃,实际上它甚至不会触发编译器警告。它已被弃用,但仍然可用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文