使用adMobs自定义每个场景

时间:2014-04-29 17:46:11

标签: ios objective-c sprite-kit

我正在使用admobs在我的场景中展示广告。我在ViewController的viewWillLayoutSubviews方法中添加了bannerview。问题是这似乎被添加到所有场景中,我只希望它添加到其中一个场景中。

这是我的代码:

-(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] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
        self.bannerView.adUnitID = @"ca-app-pub-5705189099471387/1882864952";
        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];
        GADRequest *r = [[GADRequest alloc] init];
        r.testing = YES;
        [self.bannerView loadRequest:r];
        // Create and configure the scene.
        SKScene * scene = [Menu sceneWithSize:skView.bounds.size];

        NSLog(@"%@", scene);

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


    }

}



-(void)adViewDidReceiveAd:(GADBannerView *)adView {
    NSLog(@"Ad Reveived");

    adView.frame = CGRectMake(0.0, 0.0, adView.frame.size.width, adView.frame.size.height);

}

-(GADRequest *)createRequest {
    GADRequest *request = [GADRequest request];
    request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
    return request;
}

0 个答案:

没有答案