gpt4 book ai didi

ios - AppLovin 横幅广告在 iPad 上崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:38 25 4
gpt4 key购买 nike

我正在尝试将 AppLovin 横幅广告集成到我的通用应用程序中。在 iPhone 上,它工作正常。但是在 iPad 上,当带有横幅的 View 被用户离开/关闭后,应用程序会崩溃。

这是显示横幅广告的代码:

// Create new AdView
adView = [[ALAdView alloc] initBannerAd];

//
// (Optional) Position the ad at the bottom of screen. By default
// it would be postitioned at (0,0)
//
adView.frame = CGRectMake( 0,
self.view.frame.size.height - adView.frame.size.height,
adView.frame.size.width,
adView.frame.size.height );

adView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin;

// (Mandatory) Add the ad into current view
[self.view addSubview:adView];

// (Mandatory) Trigger loading of the new ad.
[adView loadNextAd];

如果我注释掉 addSubview 调用,则不会发生崩溃。似乎添加的 subview 没有被初始化或什么的。

非常感谢您的帮助!

最佳答案

问题是没有指定父 Controller 。添加

adView.parentController = self;

解决了这个问题。这是最终代码:

// Create new AdView
adView = [[ALAdView alloc] initBannerAd];
adView.parentController = self;

// (Optional) Position the ad at the bottom of screen.
// By default it would be postitioned at (0,0)
adView.frame = CGRectMake( 0,
self.view.frame.size.height - adView.frame.size.height,
adView.frame.size.width,
adView.frame.size.height );

adView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin;

// (Mandatory) Add the ad into current view
[self.view addSubview:adView];

// (Mandatory) Trigger loading of the new ad.
[adView loadNextAd];

关于ios - AppLovin 横幅广告在 iPad 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17634389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com