簡體   English   中英

在Spritekit場景中隱藏iAd BannerView

[英]Hide iAd bannerview in spritekit scene

我正在嘗試將iads添加到新的Sprite Kit游戲中。 問題是我不需要所有場景的廣告。 我已經開始在主板上創建ADBannerView。 之后,我嘗試使用NSNotification隱藏和顯示廣告在不同的場景,但它不起作用。 即使我已添加到Menu.m(scene),廣告仍在展示:

[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil];

ViewController.m

-(void)viewWillLayoutSubviews {

    [super viewWillLayoutSubviews];
    // Configure the view.
    SKView * skView = (SKView *)self.view;
    //skView.showsFPS = YES;
    //skView.showsNodeCount = YES;
    //skView.showsPhysics = YES;


    if (!skView.scene) {


        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];



        SKScene * scene = [Menu sceneWithSize:skView.bounds.size];

        NSLog(@"%@", scene);

        // Present the scene.
        [skView presentScene:scene];






    }

}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1];
        [banner setAlpha:1];
        [UIView commitAnimations];


    }

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];


}

- (void)handleNotification:(NSNotification *)notification
{
    if ([notification.name isEqualToString:@"hideAd"]) {
        [self hidesBanner];
    }else if ([notification.name isEqualToString:@"showAd"]) {
        [self showsBanner];
    }
}


-(void)hidesBanner {

    NSLog(@"HIDING BANNER");
    [adView setAlpha:0];

}


-(void)showsBanner {

    NSLog(@"SHOWING BANNER");
    [adView setAlpha:1];


}

如果您不想顯示iAd,則創建iAd不好。

根據Apple的Banner查看最佳做法

•僅在打算將其顯示給用戶時創建橫幅視圖。 否則,它可能會在廣告中循環播放,並耗盡您應用的可用廣告列表。

•如果用戶從具有橫幅視圖的內容屏幕導航到沒有橫幅視圖的屏幕,並且您希望他們在該屏幕上停留很長時間,請從視圖層次結構中刪除橫幅視圖,將其委托設置為nil並釋放它,然后再過渡到新的內容屏幕。 更一般而言,避免在用戶看不見橫幅視圖時保持橫幅視圖。

我記得前一段時間讀過有關hidden屬性的信息,但在查看《 iAd Framework參考》時 ,我找不到任何此類屬性。 如果您不想在特定場景中展示廣告,建議您遵循Apple的准則。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM