InterstitialAd - iOS 8 beta 5 does not provide close X button in simulator

I have a problem with interstitial ads from Apple. I am making my first quick application, which I want to put in the application store as soon as possible. But when I rewrite the code for interstitial ads from obejctive-c to swift, I can show the ad, but I don't have X close buuton, so I can’t close it. I did not find anything, so I have to put this button on my own, it should be there by default. I use these functions: (I also have to say that I use a set of sprites, so my view controller automatically redirects the game to Gamescene)

func showFullScreenAd() { if requestingAd == false { interstitial = ADInterstitialAd() interstitial!.delegate = self requestingAd = true } } func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) { self.interstitial = nil requestingAd = false } func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) { if interstitialAd != nil && self.interstitial != nil && self.requestingAd == true { interstitial!.presentInView(self.view) } } func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) { interstitial = nil requestingAd = false } func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) { interstitial = nil requestingAd = false } 

Thanks for the help (here is the photo: http://imgur.com/jKTWRiG )

----- UPDATE ----- This is a solution that just works. I am doing a UIView in which I present an ad and a close button (some godmother in the background). This may not be the best solution, but the App Store acknowledged that soooo: D

All these functions are placed in GameViewController.swift (you can’t just control the view controller from the spritekit scene, you can use the gameviewcontroller singleton, it’s up to you)

 func showFullScreenAd() { if requestingAd == false { interstitial = ADInterstitialAd() interstitial!.delegate = self requestingAd = true } } func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) { self.interstitial = nil requestingAd = false } func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) { if interstitialAd != nil && _interstitial != nil && requestingAd == true { self._adView = UIView() self._adView!.frame = self.view.bounds self.view.addSubview(_adView!) self.button = UIButton(frame: CGRect(x: 10, y: 10, width: 40, height: 40)) self.button!.setBackgroundImage(UIImage(named: "close_button"), forState: UIControlState.Normal) self.button!.addTarget(self, action: Selector("close"), forControlEvents: UIControlEvents.TouchDown) self.view.addSubview(button!) _interstitial!.presentInView(self._adView) requestingAd = false } UIViewController.prepareInterstitialAds() } func close() { self._adView!.removeFromSuperview() self.button!.removeFromSuperview() self._interstitial = nil } func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) { interstitial = nil requestingAd = false self._adView!.removeFromSuperview() self.button!.removeFromSuperview() } func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) { interstitial = nil requestingAd = false self._adView!.removeFromSuperview() self.button!.removeFromSuperview() } 
+1
source share
1 answer

iOS 9.2.1, Xcode 7.2.1, ARC enabled

I am using the old method:

 [interstitial presentFromViewController:self]; 

Otherwise, the status bar is still displayed using the container view for the view, and there is no “X” button, or you are not receiving any callbacks using the suggested Apple methods, i.e.

 [self requestInterstitialAdPresentation]; [interstitial presentInView:self.view]; 

You can suppress warnings if this bothers you:

 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" //method goes here #pragma clang diagnostic pop 

Please read this post: iOS 7 iAd interstitial ads cannot be closed by user

What I am doing is attaching a presentation in this method, adding some policy with some conditions:

*. H

 #import <UIKit/UIKit.h> #import <iAd/iAd.h> #import <AssetsLibrary/AssetsLibrary.h> @interface MainViewController : UIViewController <ADInterstitialAdDelegate> { ADInterstitialAd *interstitial; } @end 

* m.

 - (void)viewDidLoad { [super viewDidLoad]; [UIViewController prepareInterstitialAds]; self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual; interstitial = [[ADInterstitialAd alloc] init]; interstitial.delegate = self; } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)presentInterlude { if (interstitial.loaded && [self shouldPresentInterstitialAd]) { [interstitial presentFromViewController:self]; } else { nil; } } #pragma clang diagnostic pop - (void)cycleInterstitial { interstitial.delegate = nil; interstitial = [[ADInterstitialAd alloc] init]; interstitial.delegate = self; } - (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd { NSLog(@"loaded"); nil; } - (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd { NSLog(@"unloaded"); [self cycleInterstitial]; } - (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error { NSLog(@"failed, error: %@", error); [self cycleInterstitial]; } - (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd { NSLog(@"finish"); } - (BOOL)interstitialAdActionShouldBegin:(ADInterstitialAd *)interstitialAd willLeaveApplication:(BOOL)willLeave { NSLog(@"action"); return true; } @end 

Then use [self presentInterlude] when you are ready to submit an interstitial ad.

To indicate when an ad is displayed and when the ad is closed using the "X" button (without clicking the contents of the ad by the user), you should take advantage of the fact that when the ad is viewDidDissapear: and when the ad is closed viewDidAppear: If you have content that needs to be ready before calling viewDidAppear: use the viewWillAppear: method.

Remember to include the interstitial cycle after each presentation, the interstitial ad will be released after the presentation, which represents the biggest difference between an interstitial ad and a banner type ad.

If anyone has a better solution, please share and send a message!

Thanks! Greetings.

0
source

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


All Articles