Landscape/Horizontal Ads

Hello again, apple community! So Ive recently been trying to implement interstitial iads into my game. Ive had very little look however i manged to get it working yesterday. The project I was using to test the ads was in portrait and this was working fine. However, when I swapped the app to run in horizontal/landscape mode the "didFailWithError" method was called indicating that the ad had failed (also the NSLog printed the following in to the console - "FAILED"). The following code is what I am working with (This code is in my GameScene Class) :


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if (adShowing == false) {

[self loadInterstitialAd];

}

}

-(void)update:(CFTimeInterval)currentTime {

/ Called before each frame is rendered */


/

if (adShowing == true) {

NSLog(@"TRUE");

} else {

NSLog(@"FALSE");

}

*/

}

-(void) loadInterstitialAd {

/

[self.delegate showInterstitialAd];

_interstitialAd = [[ADInterstitialAd alloc] init];

_interstitialAd.delegate = self;

adShowing = true;

}

-(void) interstitialAdWillLoad:(ADInterstitialAd *)interstitialAd {

}

-(void) interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {


interstitialAdView = [[UIView alloc] init];

interstitialAdView.frame = (self.view.bounds);

[self.view addSubview:interstitialAdView];


[_interstitialAd presentInView:interstitialAdView];

[UIViewController prepareInterstitialAds];

}

-(void) interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {

[interstitialAdView removeFromSuperview];

adShowing = false;

}

-(void) interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {

NSLog(@"FAILED");

/

}

-(void) interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd{

/

}



Thanks in advance! 🙂


Kind Regards

Ryan

Ryan-


Please see my response in the other thread: https://forums.developer.apple.com/thread/24241. The approach I suggest worked as expected when rotating between portrait and landscape.


Two items of note: (1) call UIViewController.prepareInterstitialAds() as early in your app as possible and (2) the interstitial itself can appear in landscape or portrait, but once the user taps on it, the expanded ad unit may change orientation per the advertiser's creative.


-Josh

Still not working, I tried to adapt your code but it was in swift so it was hard to interpret but it didnt help. Its the error Im getting thats confusing. No ads are loading because of the orientation, that doesnt make much sense if you ask me....


Any more ideas? 🙂


Kind Regards

Ryan

Its confusing too because it works PERFECTLY in portrait, spot on. But as soon as I change it to landscape only in the project settings it now refuses to find/load ads so the inventory is always empty :/

I would also like to point out that this is the error I am getting:


Code=3 "The operation couldn’t be completed. Ad inventory unavailable"

You are likely getting this error because the frame for the interstitial in landscape is not sized properly.

Well this code here is in my interstitialDidLoad Method:


interstitialAdView = [[UIView alloc] init];

interstitialAdView.frame = (self.view.bounds);

[self.view addSubview:interstitialAdView];

[_interstitialAd presentInView:interstitialAdView];



Is that not right?

Landscape/Horizontal Ads
 
 
Q