mardi 27 janvier 2015

how to code iAd/AdMob in methods other than viewDidLoad

iAd/AdMob mediation works in viewDidLoad. How do I put iAd/AdMob mediation in other methods? Doesn't seem to work. Only works in viewDidLoad.


The following code is in my GameOver method...



if (self.admobBannerView.hidden==YES) {


self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, 320.0f, 50.0f)];
[self.bannerView setDelegate:self];
[self.view addSubview:self.bannerView];
[self.bannerView setAlpha:1];

self.bannerView.hidden=NO;

}
else
{

[self.bannerView setAlpha:0];

self.bannerView.hidden=YES;


admobBannerView=[[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];


self.admobBannerView.adUnitID = @"Unit-ID";
self.admobBannerView.rootViewController = self;
self.admobBannerView.delegate = self;


[self.view addSubview:self.admobBannerView];

GADRequest *request =[GADRequest request];

request.testDevices= @[ GAD_SIMULATOR_ID ];

[self.admobBannerView loadRequest:request];
}


I placed the above method in viewDidLoad and mediation works fine, however, the above method doesn't work in GameOver method. Only AdMob always loads and never iAd.


I also used bannerViewDidLoadAd method that states show iAd. Then didFailToReceiveAdWithError method to says iAd is hidden and AdMob loads.


I've been trying for 2 weeks and can't get GameOver method to mediate iAd/AdMob. So is it possible to even do mediation in methods other than viewDidLoad? How is it done?




Aucun commentaire:

Enregistrer un commentaire