为什么 iAd 在从其超级视图中删除数据后仍然加载数据,并且可以停止这种情况吗?

发布于 2024-11-07 03:24:21 字数 840 浏览 6 评论 0原文

我有一个带有 iAds 的小应用程序,允许人们付费升级。

iAd 在应用程序的 NIB 中设置。我在主 UIViewController 的 viewDidLoad 方法中检查购买状态,并在 ADBannerView 出口成员上调用以下方法:

[adBanner removeFromSuperview];
adBanner = nil;

不幸的是,如果我观察设备的数据使用情况,一些数据仍会下载该广告。

有没有办法正确终止 iAd,使其不加载任何数据?

我知道我可以以编程方式创建 iAd 视图,然后仅在用户尚未购买该产品时添加它,但我的产品在 NIB 上运行良好,因此我不想更改它。

更新:

在我的 .h 文件中,我有:

IBOutlet ADBannerView* adBanner;

- (void)viewDidLoad 方法中的 .m 文件中,我有:

if (purchased) {
    [adBanner removeFromSuperview];
    adBanner.delegate = nil;
    adBanner = nil;
}

我希望这足以在 iAd 有机会下载之前删除它任何数据。

唉,这还不足以阻止视图下载数据。我怀疑当时完全释放它有延迟 - 但我不知道如何做到这一点,除了调用 dealloc 本身。

有谁知道更好/正确的方法来完全销毁通过 XIB 加载并分配给 IBOutlet 的对象?

I have a small app with iAds, and allow people to pay to upgrade.

The iAd is setup in the application's NIB. I check the purchase status in the viewDidLoad method of the main UIViewController, and call the following methods on the ADBannerView outlet member:

[adBanner removeFromSuperview];
adBanner = nil;

Unfortunately if I watch the device's data usage, some data is still downloaded for the Ad.

Is there any way to properly kill the iAd so it doesn't load any data?

I know I could create the iAd view programatically and then add it only if the user has not purchased the product, but my product is working nicely from the NIB and I'd rather not change it for this reason.

UPDATE:

In my .h file I have:

IBOutlet ADBannerView* adBanner;

In the .m file in - (void)viewDidLoad method I have:

if (purchased) {
    [adBanner removeFromSuperview];
    adBanner.delegate = nil;
    adBanner = nil;
}

I would hope this would be enough to remove the iAd before it gets a chance to download any data.

Alas, this isn't enough to prevent the view from downloading data. I suspect there is a delay in it being fully dealloc'd at that time – but I don't know how to do this, short of calling dealloc itself.

Does anyone know of a better/correct way to completely destroy an object loaded via the XIB and assigned to an IBOutlet?

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

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

发布评论

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

评论(4

梦里梦着梦中梦 2024-11-14 03:24:21

我怀疑你没有完全释放广告横幅。

您在创建 adBanner 时是否自动释放了它?如果没有,您在此处显示的代码将无法正确释放横幅。

最有可能的是,您没有自动释放它并且它被保留了。您需要做的是:

[adBanner release]; 

相反

adBanner = nil;

,它是无用的,因为它仅将指针 adBanner 设置为 nil 但根本不释放对象。

I suspect you don't completely release the ad banner.

Did you autorelease the adBanner when creating it? If you didn't, the code you are showing here doesn't properly release the banner.

Most likely, you didn't autorelease it and it's retained. What you need to do is:

[adBanner release]; 

instead of

adBanner = nil;

which is by the way useless since it only sets the pointer adBanner to nil but doesn't release the object at all.

つ低調成傷 2024-11-14 03:24:21

我想你必须使用第二个笔尖,没有 iAd 横幅。 nib 加载过程将在将控制权传递回对象之前实例化 nib 的所有元素。这就是为什么您无法阻止 iAd 尝试加载广告。

首先,复制当前笔尖,然后删除 iAd 横幅视图。然后重写视图控制器的 initWithNibName:bundle: 方法来检查付费状态。如果付费,请将笔尖名称更改为非 iAd 笔尖,并使用另一个笔尖调用超类的方法。

I think you'll have to use a second nib, without the iAd banner. The nib loading process will instantiate all elements of the nib before passing control back to your objects. That's why you can't stop the iAd from trying to load an ad.

First, duplicate the current nib, and just delete the iAd banner view. Then override the view controller's initWithNibName:bundle: method to check for paid status. If paid, change the nib name to the non iAd nib, and call the superclass's method with the other nib.

早乙女 2024-11-14 03:24:21

您还可以设置 adBanner.delegate = nil 来阻止 adBanner 与其委托进行通信。

You could set the adBanner.delegate = nil also, to stop the adBanner from communicating with it's delegate.

余生一个溪 2024-11-14 03:24:21

@mr-berna 是对的,您需要有条件地加载 iAd 视图。您可以按照他的建议操作并使用第二个笔尖,或者以编程方式创建 iAd 视图。

@mr-berna is right in that you need to conditionally load the iAd view. You can either do as he suggests and use a second nib or create the iAd view programmatically.

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