在InterstitialAd - iOS设备8测试版5没有提供模拟器X关闭按钮 [英] interstitialAd - iOS 8 beta 5 does not provide X close button in simulator

查看:191
本文介绍了在InterstitialAd - iOS设备8测试版5没有提供模拟器X关闭按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个苹果插页式广告的问题。我在做我的第一次迅速的应用程序,这是我想要把应用程序商店,只要这将是可能的。但是,当我重​​写code从obejctive-C可迅速插页广告,我能够显示广告,但我没有X,关闭buuton,所以我不能关闭它。我还没有发现anywher,taht我应该把我自己的这个按钮,它应该存在默认情况下。我使用这个功能:(我也不得不说,我使用精灵套件,所以我的视图控制器automaticaly重定向游戏Gamescene)

  FUNC showFullScreenAd(){    如果requestingAd == {假        间质性= ADInterstitialAd()
        间质性!.delegate =自        requestingAd =真    }}FUNC在InterstitialAd(在InterstitialAd:ADInterstitialAd!didFailWithError错误:NSError){
    self.interstitial =零
    requestingAd = FALSE}FUNC interstitialAdD​​idLoad(在InterstitialAd:ADInterstitialAd!){    如果在InterstitialAd =零和放大器;!&安培; self.interstitial =零和放大器;!&安培; self.requestingAd ==真{        间质性!presentInView(self.view)    }
}
FUNC interstitialAdD​​idUnload(在InterstitialAd:ADInterstitialAd!){
    间质性=零
    requestingAd = FALSE
}
FUNC interstitialAdActionDidFinish(在InterstitialAd:ADInterstitialAd){
    间质性=零
    requestingAd = FALSE
}

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

----- -----更新
这是解决方案,这只是工作。我做的UIView,我在其中present广告和关闭按钮(在后台一些交叉的图像)。这可能不是最好的解决办法,但应用程序商店接受,SOOOO:D

所有这些funcs中被放置在GameViewController.swift(你不能简单地控制视图从spritekit现场控制器,你可以通过gameviewcontroller的单,它是由你)

  FUNC showFullScreenAd(){    如果requestingAd == {假        间质性= ADInterstitialAd()
        间质性!.delegate =自        requestingAd =真    }}
FUNC在InterstitialAd(在InterstitialAd:ADInterstitialAd!didFailWithError错误:NSError){
    self.interstitial =零
    requestingAd = FALSE}FUNC interstitialAdD​​idLoad(在InterstitialAd:ADInterstitialAd!){    如果在InterstitialAd =零和放大器;!&安培; _interstitial =零和放大器;!&安培; requestingAd ==真{        self._adView = UIView的()
        self._adView!.frame = self.view.bounds
        self.view.addSubview(_adView!)        self.button =的UIButton(帧:的CGRect(X:10 Y:10,宽40,高:40))
        !self.button .setBackgroundImage(的UIImage(命名为:close_button),forState:UIControlState.Normal)
        !self.button .addTarget(个体经营,动作:选择器(亲密),forControlEvents:UIControlEvents.TouchDown)
        self.view.addSubview(按钮!)        _interstitial!presentInView(self._adView)
        requestingAd = FALSE
    }
    UIViewController中。prepareInterstitialAds()
}
FUNC接近(){    self._adView!.removeFromSuperview()
    self.button!.removeFromSuperview()
    self._interstitial =零}FUNC interstitialAdD​​idUnload(在InterstitialAd:ADInterstitialAd!){
    间质性=零
    requestingAd = FALSE
    self._adView!.removeFromSuperview()
    self.button!.removeFromSuperview()
}
FUNC interstitialAdActionDidFinish(在InterstitialAd:ADInterstitialAd){
    间质性=零
    requestingAd = FALSE
    self._adView!.removeFromSuperview()
    self.button!.removeFromSuperview()
}


解决方案

的iOS 9.2.1,X code 7.2.1,支持ARC

我使用的老方法:

  [间质性presentFromViewController:个体经营];

否则,状态栏依然采用鉴于容器以present显示并没有X按钮,或者你使用由苹果公司所提出的方法没有回调,即:

  [自requestInterstitialAd presentation]。
[间质性presentInView:self.view];

您可以共进晚餐preSS的警告,如果你烦恼:

 的#pragma铛诊断推
铿锵的#pragma忽略诊断-Wde precated-声明//方法进入这里的#pragma铛诊断流行

请阅读这篇文章:的iOS 7 iAd的插页式广告不能由用户

关闭

我做的是附上presentation在像这样的方法,具有一定的条件来增加一些修饰:

*的.h

 #进口<的UIKit / UIKit.h>
#进口< IAD / iAd.h>
#进口< AssetsLibrary / AssetsLibrary.h>@interface MainViewController:的UIViewController< ADInterstitialAdD​​elegate>
{
    ADInterstitialAd *质;
}@结束

*:M

   - (无效)viewDidLoad中
{
    [超级viewDidLoad中];    [UIViewController的prepareInterstitialAds]。
    self.interstitial presentationPolicy = ADInterstitial presentationPolicyManual;    间质性= [[ADInterstitialAd的alloc]初始化];
    interstitial.delegate =自我;
}的#pragma铛诊断推
铿锵的#pragma忽略诊断-Wde precated-声明 - (无效)presentInterlude
{
    如果(interstitial.loaded&安培;&安培;自应presentInterstitialAd])
    {
        [间质性presentFromViewController:个体经营];
    }
    其他
    {
        零;
    }
}的#pragma铛诊断流行 - (无效)cycleInterstitial
{
    interstitial.delegate =零;
    间质性= [[ADInterstitialAd的alloc]初始化];
    interstitial.delegate =自我;
} - (无效)interstitialAdD​​idLoad:(ADInterstitialAd *)在InterstitialAd
{
    的NSLog(@装);
    零;
} - (无效)interstitialAdD​​idUnload:(ADInterstitialAd *)在InterstitialAd
{
     的NSLog(@卸载);    [个体经营cycleInterstitial]
} - (无效)在InterstitialAd:(ADInterstitialAd *)在InterstitialAd didFailWithError:(NSError *)错误
{
     的NSLog(@失败,错误:%@,错误);    [个体经营cycleInterstitial]
} - (无效)interstitialAdActionDidFinish:(ADInterstitialAd *)在InterstitialAd
{
    的NSLog(@完成);
} - (BOOL)interstitialAdActionShouldBegin:(ADInterstitialAd *)在InterstitialAd willLeaveApplication:(BOOL)willLeave
{
    的NSLog(@行动);    返回true;
}@结束

然后使用 [自presentInterlude] 当你准备present插页式广告。

要告诉时显示的广告,当广告用X按钮(无需用户点击广告的内容)关闭,你必须采取的事实,即在显示广告 viewDidDissapear:被调用,而当广告被关闭 viewDidAppear:被调用。如果你有 viewDidAppear之前的一些内容需要做好准备:被调用,然后使用 viewWillAppear中:方法

不要忘了周期中的每个presentation后的间隙,间隙的广告对象被后presentation,这是插页广告和横幅广告类型之间最大的区别释放。

如果有人有更好的解决方案,那么请共享和发布!

谢谢!干杯。

I have a problem with interstitial ads from Apple. I'm doing my first app in swift, which I want to put on App store, as soon as it will be possible. But when I rewrite code for interstitial ads from obejctive-c to swift, I am able to show up the ad, but i does not have X close buuton, so I can not close it. I have not found anywher, taht I should place this button on my own, it should be there by default. I am using this functions: (I also have to say, that I'm using sprite kit, so my view controller automaticaly redirects 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 
}

Thank you for help (here is a picture: http://imgur.com/jKTWRiG)

-----UPDATE----- This is solution, which just works. I make UIView, in which I present ad and close button (some cross image on background). This may not be the best solution, but app store accepted that, soooo :D

All these funcs are placed in GameViewController.swift (you can't simply control view controller from spritekit scene, you could through singleton of gameviewcontroller, it is 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() 
}

解决方案

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 shown using a container view to present in view and there is no "X" button, or you get no call backs using the suggested methods by Apple, i.e:

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

You can suppress the warnings if it 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 can not be closed by user

What I do is enclose the presentation in a method like so, add some polish 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 present the interstitial ad.

To tell when the ad is displayed and when the ad is closed using the "X" button (without the user clicking the ad content), you must take advantage of the fact that when the ad is displayed viewDidDissapear: is called, and when the ad is closed viewDidAppear: is called. If you have some content that needs to be ready before viewDidAppear: is called, then use the viewWillAppear: method.

Don't forget to cycle the interstitial after each presentation, the interstitial ad object gets released after presentation, which is the biggest difference between an interstitial ad and a banner type ad.

If someone has a better solution, then please share and post!

Thanks! Cheers.

这篇关于在InterstitialAd - iOS设备8测试版5没有提供模拟器X关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆