Strange behavior with iAd Interstitial

I am experiencing some kind of strange behavior in both ios7 and 8 ..

What happens, sometimes the full screen is presented using X (POTRAIT FUllSCREEN AD - my application is for landscape only). You press X and you can return to your menu in order.

But sometimes an ad appears without X (LANDSCAPE FUllSCREEN AD). If you wait for DiDFinish delegate NEVER, it is called. So I'm trying to click it to leave. He then shows another ad with X (LANDSCAPE FUllSCREEN AD). So I press X. Then it goes to another declaration (LANDSCAPE FUllSCREEN AD) where DiDFinish is DiDFinish . iOS7, it will simply freeze from the third ad shown. Will ios8 show a third ad for a second and then go black? Has anyone dealt with something like this?

Not sure if the first ad is displayed in portrait orientation, it works great, is that the key or not?

Several ad impressions are also shown: iAd not rev mob and iAd are combined because I have a 100 percent fill rate for iAd. right now i'm just trying to get iAds fullscreen ads to work consistently

I know that the delegate is set as didLoad delegate gets a call when the announcement is loaded. This is also a problem for both iPhone and iPad.

Anyone else had problems?

Using..

 [interstitial presentFromViewController:self]; 

Instead..

 [interstitial presentInView:self.view]; 

does everything right, but presentFromViewController: now deprecated

enter image description here

Here is my code that I use ...

 -(void)showFullScreenAd { //Check if already requesting ad if (requestingAd == NO) { //[ADInterstitialAd release]; interstitial = [[ADInterstitialAd alloc] init]; interstitial.delegate = self; self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual; [self requestInterstitialAdPresentation]; NSLog(@"interstitialAdREQUEST"); requestingAd = YES; } } -(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error { interstitial = nil; requestingAd = NO; NSLog(@"interstitialAd didFailWithERROR"); NSLog(@"%@", error); [revmobFS loadWithSuccessHandler:^(RevMobFullscreen *fs) { [fs showAd]; NSLog(@"Ad loaded"); } andLoadFailHandler:^(RevMobFullscreen *fs, NSError *error) { NSLog(@"Ad error: %@",error); } onClickHandler:^{ NSLog(@"Ad clicked"); } onCloseHandler:^{ NSLog(@"Ad closed"); }]; } -(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd { NSLog(@"interstitialAdDidLOAD"); if (interstitialAd != nil && interstitial != nil && requestingAd == YES) { [interstitial presentInView:self.view]; NSLog(@"interstitialAdDidPRESENT"); }//end if } -(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd { interstitial = nil; requestingAd = NO; NSLog(@"interstitialAdDidUNLOAD"); } -(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd { interstitial = nil; requestingAd = NO; NSLog(@"interstitialAdDidFINISH"); } 

if someone can just post there code that works completely there, the app for me to try will also earn +50 reputation

+5
source share
1 answer

There is no working code from my end, but I looked through the documentation and found catergory for UIViewController with iAd methods

Here

It seems you are mixing old code with new code.

From what I saw, I would suggest:

  -(void)showFullScreenAd { //Check if already requesting ad if (requestingAd == NO) { [self requestInterstitialAdPresentation]; requestingAd = YES; } } -(void)viewDidLoad() { [super viewDidLoad]; // Any other setup. self.ADInterstitialPresentationPolicy = ADInterstitialPresentationPolicyManual } 

This follows the new iOS7 implementation. Setting a policy in the viewDidLoad method allows the platform to pre-cache assets and run any ads from the iAd server. Ready, therefore, when the showFullScreenAd method is called, the advertisement must be ready.

You can also call the class method +(void)prepareInterstitialAds when loading the view or performing other data tasks, this allows you to use the resources of the preliminary cache of the Framework, if possible, which can mean subsequent requests faster.

To handle RevMob with an advertisement error: [self requestInterstitialAdPresentation]; returns a boolean, which means you can handle this and report a RevMob error, etc. When the ad was closed. It is best to do some KVO in the presentingFullScreenAd property for the ViewController. Which indicates whether it shows FullScreenAd, I believe that this is only iAd, Full Ad.

The reason you have such different results is because you have two ways to request and declare ads in the same view controller.

When an ad is presented "Portrait", [self requestInterstitialAdPresentation]; Failed to get the declaration, but the instance of ADInterstitialAd sent another request. This loaded because you do not set the frame to represent the instance, it does not know that it is intended for landscape and therefore a portrait version is presented. Since it is now presented in the view, the view does not know / does not care about what orientation it is in, therefore it is an advertising view based on its geometry.

When is the landscape below [self requestInterstitialAdPresentation]; . This top announcement is the announcement of this call. I'm not sure why the rest of the screen shows a landscape, unless it's something from the Framework, that is, [self requestInterstitialAdPresentation]; internally decides that it should be a landscape from the ViewControllers layout, so all subsequent ad requests match this if the VC orientation does not change again.

[EDIT] - I put together an example. This was made from memory / documentation, so it probably won’t be 100% correct and most likely will not work with direct copy and paste. This should give an idea that also includes support for pre iOS7 versions

 //.h @import UIKit; @import iAd; @interface MyInterstitialViewController : UIViewController <ADInterstitialAdDelegate> { } @property (strong) ADInterstitialAd *fullScreenAd; @end //.m #include MyInterstitialViewController.h @implementation MyInterstitialViewController { - (instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle { if(self = [super initWithNibName:nibName bundle:nibBundle]) { } return self; } -(void)viewDidLoad() { [super viewDidLoad]; if([self respondsToSelector:@selector(requestInterstitialAdPresentation)] == YES) { self.ADInterstitialPresentationPolicy = ADInterstitialPresentationPolicyManual; } } -(void)viewWillDisappear { @try { **[self removeObserver:self forKeyPath:@"isPresentingFullScreenAd"];** } @catch (NSException * __unused exception) { } } -(void)showFullScreenAd() { if([self respondsToSelector:@selector(requestInterstitialAdPresentation)] == NO) { self.fullScreenAd = [[ADInterstitialAd alloc] init]; self.fullScreenAd.delegate = self; } else { if([self requestInterstitialAdPresentation] == NO) { //Report back to RevMob Controller that the Ad Failed. [revmobFS loadWithSuccessHandler:^(RevMobFullscreen *fs) { [fs showAd]; NSLog(@"Ad loaded"); } andLoadFailHandler:^(RevMobFullscreen *fs, NSError *error) { NSLog(@"Ad error: %@",error); } onClickHandler:^{ NSLog(@"Ad clicked"); } onCloseHandler:^{ NSLog(@"Ad closed"); }]; } else { **[self addObserver:self forKeyPath:@"isPresentingFullScreenAd" options:NSKeyValueObservingOptions.NSKeyValueObservingOptionNew context:nil];** } } } //ADInterstitialAd Delegate Methods. -(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error { interstitial = nil; NSLog(@"interstitialAd didFailWithERROR"); NSLog(@"%@", error); [revmobFS loadWithSuccessHandler:^(RevMobFullscreen *fs) { [fs showAd]; NSLog(@"Ad loaded"); } andLoadFailHandler:^(RevMobFullscreen *fs, NSError *error) { NSLog(@"Ad error: %@",error); } onClickHandler:^{ NSLog(@"Ad clicked"); } onCloseHandler:^{ NSLog(@"Ad closed"); }]; } -(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd { NSLog(@"interstitialAdDidLOAD"); if (self.fullScreenAd != nil) { CGRect interstitialFrame = self.view.bounds; interstitialFrame.origin = self.view.origin; UIView *view = [[UIView alloc] initWithFrame:interstitialFrame]; [self.view addSubview:view]; [self.fullScreenAd presentInView:view]; NSLog(@"interstitialAdDidPRESENT"); }//end if } -(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd { NSLog(@"interstitialAdDidUNLOAD"); } -(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd { NSLog(@"interstitialAdDidFINISH"); } //KVO Responding - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { **if([keyPath isEqualTo:"isPresentingFullScreenAd"] == YES) { if([object === self]) { if([self isPresentingFullScreenAd] == false) { //Handle logic for your app. New Screen etc. } else { //Handle logic for your app. Pause current activity etc. } } }** } } 

For reference.

The changes I made allow the Ad Framework to work the way you expect on all versions of iOS from 4.3 to 8.X

From iOS 4.3 - 6.X, the overall thread was:

Create an announcement, set it to delegate, submit and process in the delegate methods.

From 7 to 8.X (the previous presentation method in the UIViewController was deprecated in iOS 7, but deprecation means that previous methods work until the next version of X.0, as a rule.)

In this case, you request the Framework to declare through [UIViewController requestInterstitialAdPresentation]; method. The controller will create the view and present it if it has an advertisement. You no longer get delegate methods, "- (void) observValueForKeyPath: (NSString *) keyPath ofObject: (ID) object change: (NSDictionary *) change context: (void *) context"

the method essentially allows you to get a delegate call when the ad has finished serving so you can continue the logic of your application. In essence, calling the delegate is "AdDidFinish." But since we do not remove the observer until the controller is unloaded, there is logic to handle if a new advertisement was displayed.

This means that your VC logic should not check to see if a full-screen ad is constantly displayed.

You can still use the stream from iOS 4.3-6.8, but using the presentInView method. As described in the iAd Programming Guide, this should be used if you have a view of the content inside, then what I have outlined is a Transitional Announcement methodology.

+3
source

Source: https://habr.com/ru/post/1207244/


All Articles