我正在尝试将AppLovin Banner Ads集成到我的Universal App中。在iPhone上,它工作正常。但是在iPad上,在用户留下/解散横幅后,应用程序崩溃了。
以下是展示横幅广告的代码:
// 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调用,则不会发生崩溃。似乎添加的子视图没有得到单一化或某种东西。
非常感谢您的帮助!
答案 0 :(得分:3)
问题是未指定父控制器。添加
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];