interstitialAd - iOS 8 beta 5在模拟器中不提供X关闭按钮

时间:2014-08-13 11:48:29

标签: ios button swift iad interstitial

我对Apple的插页式广告有疑问。我正在快速做我的第一个应用程序,我希望尽快将其放在App Store上。但是当我将插页式广告的代码从obejctive-c重写为swift时,我能够显示广告,但我没有X关闭buuton,所以我无法关闭它。我没有找到任何东西,我应该把这个按钮放在我自己的位置,它应该默认存在。我正在使用这个函数:(我也不得不说,我正在使用精灵工具包,所以我的视图控制器自动将游戏重定向到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 
}

感谢您的帮助(这是图片:http://imgur.com/jKTWRiG

- - - - - - - - UPDATE 这是解决方案,只是有效。我制作了UIView,其中我展示了广告和关闭按钮(背景上的一些交叉图像)。这可能不是最好的解决方案,但app store接受了,soooo:D

所有这些func都放在GameViewController.swift中(你不能简单地从spritekit场景控制视图控制器,你可以通过gameviewcontroller的单例,它取决于你)

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 个答案:

答案 0 :(得分:0)

iOS 9.2.1,Xcode 7.2.1,启用了ARC

我使用旧方法:

[interstitial presentFromViewController:self];

否则,仍会显示状态栏,使用容器视图显示在视图中,并且没有" X"按钮,或者您使用Apple建议的方法没有回拨,即:

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

如果您遇到麻烦,可以取消警告:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

//method goes here

#pragma clang diagnostic pop

请阅读这篇文章:iOS 7 iAd interstitial ads can not be closed by user

我所做的是将演示文稿包含在这样的方法中,在某些条件下添加一些润色:

<强> *的.h

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import <AssetsLibrary/AssetsLibrary.h>

@interface MainViewController : UIViewController <ADInterstitialAdDelegate>
{
    ADInterstitialAd *interstitial;
}

@end

<强> *米

- (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

当您准备好展示插页式广告时,请使用[self presentInterlude]

使用&#34; X&#34;判断广告何时展示以及何时关闭广告按钮(用户无需点击广告内容),您必须利用以下事实:在广告显示时viewDidDissapear:被调用,广告关闭时viewDidAppear:被调用。如果您在调用viewDidAppear:之前需要准备一些内容,请使用viewWillAppear:方法。

不要忘记在每次演示后循环插页式广告,插页式广告对象会在展示后发布,这是插页式广告和横幅广告之间的最大区别。

如果有人有更好的解决方案,请分享并发布!

谢谢!欢呼声。