Ios 在精灵套件场景中集成adMobs
我正在尝试将admobs集成到场景中。我试图通过在viewController中执行viewWillLayoutSubviews来实现这一点。我正在一个有0个节点的空白场景中尝试,因此没有任何东西会在场景中导致问题 问题是广告没有出现在我的场景中。我收到以下日志消息:Ios 在精灵套件场景中集成adMobs,ios,iphone,objective-c,sprite-kit,Ios,Iphone,Objective C,Sprite Kit,我正在尝试将admobs集成到场景中。我试图通过在viewController中执行viewWillLayoutSubviews来实现这一点。我正在一个有0个节点的空白场景中尝试,因此没有任何东西会在场景中导致问题 问题是广告没有出现在我的场景中。我收到以下日志消息: To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ]; 但是我正在createRequest方法中创建请求 这是我的代
To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ];
但是我正在createRequest方法中创建请求
这是我的代码:
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
if (!skView.scene) {
self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
self.bannerView.adUnitID = @"ca-app-pub-AdId";
self.bannerView.rootViewController = self;
self.bannerView.delegate = self;
self.bannerView.center = CGPointMake(skView.bounds.size.width / 2, skView.bounds.size.height - (bannerView_.frame.size.height / 2));
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[GADRequest request]];
// Create and configure the scene.
SKScene * scene = [Menu sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
-(GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
return request;
}
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"Ad Reveived");
[UIView animateWithDuration:1.0 animations:^{
adView.frame = CGRectMake(0.0, 0.0, adView.frame.size.width, adView.frame.size.height);
}];
}
您需要替换以下代码
[self.bannerView loadRequest:[GADRequest request]];
with:
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[self.bannerView loadRequest:r];
希望这对您有用。您面临的问题是什么?同样要提到这一点。但是你在哪里调用这个createRequest函数呢?在ViewController.m文件中看起来很好,但是如何在特定场景中删除横幅呢+