3

I am trying to integrate AppLovin Banner Ads into my Universal App. On iPhone, it works fine. But on iPad, there is a crash of the app after the view with the banner is left/dismissed by the user.

Here is the code to show the banner ad:

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

If I comment out the addSubview invocation, no crash occurs. It seems like the added subview does not get unitialized or something.

Your help is much appreciated!

Guru
  • 21,652
  • 10
  • 63
  • 102
user1006117
  • 431
  • 4
  • 16

1 Answers1

3

The problem was that the parent controller was not specified. Adding

adView.parentController = self;

solved the problem. Here is the final code:

// 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];
user1006117
  • 431
  • 4
  • 16