gpt4 book ai didi

ios - 在 Sprite Kit 场景中隐藏 iAd

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:36 24 4
gpt4 key购买 nike

我已使用以下代码将 iAds 添加到我的 Sprite Kit 游戏中:

在viewController.h文件中

@property (strong, nonatomic) IBOutlet ADBannerView * adBannerView;

在viewController.m文件中

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];

// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {

// Create and configure the scene.
SKScene * scene = [MenuScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

_adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
_adBannerView.delegate = self;
[_adBannerView setFrame:CGRectMake(0, 0, 460, 320)];
[self.view addSubview:_adBannerView];

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

这显示了每个场景中的 iAd。有没有办法在某些场景隐藏iAd?

Apple 的 iAd 编程指南说:

Only create a banner view when you intend to display it to the user. Otherwise, it may cycle through ads and deplete the list of available advertising for your application.

这在场景中完全可能吗?

最佳答案

是的,有一种方法可以在某些场景中隐藏 iAd。

- (void)viewDidLoad
{

[super viewDidLoad];

//Add view controller as observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];

// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;

// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

// Present the scene.
[skView presentScene:scene];
self.canDisplayBannerAds = YES;

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 0.0f);
adView.delegate=self;
[self.view addSubview:adView];

self.bannerIsVisible=NO;
}
//Handle Notification
- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:@"hideAd"]) {
[self hidesBanner];
} else if ([notification.name isEqualToString:@"showAd"]) {
[self showBanner];
}
}

在你想要隐藏横幅的场景中......

[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil]; 
//Sends message to viewcontroller to show ad.

[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil];
//Sends message to viewcontroller to hide ad.

关于ios - 在 Sprite Kit 场景中隐藏 iAd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com