在精灵套件场景中集成adMobs

时间:2014-04-29 08:22:28

标签: ios iphone objective-c sprite-kit

我试图将" admobs" 整合到一个场景中。我试图通过viewWillLayoutSubviews中的viewController来做到这一点。我在 0 节点的空白场景中进行尝试,因此没有什么可以导致场景出现问题。

问题是广告没有在我的场景中显示。我收到了以下日志消息:

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

1 个答案:

答案 0 :(得分:0)

您需要替换以下代码;

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

 with:

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

希望这适合你。