简体   繁体   English

将adMobs整合到Sprite Kit场景中

[英]Integrating adMobs in sprite kit scene

I'm trying to integrate "admobs" into an scene. 我正在尝试将“ admob”集成到场景中。 I'm trying to do that by doing it viewWillLayoutSubviews in the viewController . 我正在尝试通过在viewController执行viewWillLayoutSubviews来做到这viewController I'm trying it out in a blank scene with 0 nodes, so there is nothing that can cause problems in the scene. 我正在一个有0个节点的空白场景中进行尝试,因此没有什么可以导致场景出现问题。

The problem is that the ad is not showing in my scene. 问题在于该广告未在我的场景中展示。 I'm getting following log message: 我收到以下日志消息:

To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ];

but i am creating the request in createRequest method. 但我在createRequest方法中创建请求。

This is my code: 这是我的代码:

-(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);
    }];
}

You need to replace the following code; 您需要替换以下代码;

[self.bannerView loadRequest:[GADRequest request]];

 with:

GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[self.bannerView loadRequest:r];

Hope this works for you. 希望这对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM