I implemented for iAds to works in bannerViewDidLoadAd method and then I implemented for AdMob to work in didFailToReceiveAdWithError method. However, on the same view controller I have a GameOver method where I want ad to appear. Only iAds load on GameOver method, AdMob doesn't. Also, when iAds fail to load AdMob doesn't load. It seems to me since I added the GADBannerView programmatically onto Storyboards the game never responds to _bannerView.hidden=YES or NO. Since i Added the ADBannerView from Object Library in Xcode, the game only responds to iAdBanner.hidden=YES or NO. Why doesn't AdMob respond to a programmatically added Ad banner?
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[iAdBanner setAlpha:1];
iAdBanner.hidden=NO;
[UIView commitAnimations];
[self.iAdBanner setDelegate:self];
_bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[iAdBanner setAlpha:0];
iAdBanner.hidden=YES;
[UIView commitAnimations];
_bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
_bannerView=[[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
self.bannerView.adUnitID=#"UNIT-ID";
self.bannerView.rootViewController=self;
[self.view addSubview:self.bannerView];
self.bannerView.delegate = self;
GADRequest *request =[GADRequest request];
request.testDevices= #[ GAD_SIMULATOR_ID ];
[self.bannerView loadRequest:request];
}
Related
for iOS, iAd/AdMob mediation only works in viewDidLoad method. It completely ignores every other method. Since iAd is added through storyboards and AdMob is added programmatically, AdMob doesn't respond to .hidden statements. Since the mediation only works in ViewDidLoad, how do I make mediation work in -(void)GameOver method for example?
For example...
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{}
How Would I place the above method inside of the -(void)GameOver method so the code inside the didFailToReceiveAdWithError would work in -(void)GameOver?
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[iAdBanner setAlpha:1];
iAdBanner.hidden=NO;
[UIView commitAnimations];
[self.iAdBanner setDelegate:self];
bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[iAdBanner setAlpha:0];
iAdBanner.hidden=YES;
[UIView commitAnimations];
bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView=[[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
self.bannerView.adUnitID=#"Unit-ID";
self.bannerView.rootViewController=self;
[self.view addSubview:self.bannerView];
GADRequest *request =[GADRequest request];
request.testDevices= #[ GAD_SIMULATOR_ID ];
[self.bannerView loadRequest:request];
}
Ok, so after testing on the simulators it turns out that this issue is only occurring on actual devices... How would I fix this?
I am making an iOS app with SpriteKit and am implementing iAD. Everything works more or less like I expect it too, except for one thing. When I tap on the ad, it brings me to a full screen ad, as expected, but when I close that ad the current view freezes, as in nothing happens visually. I know the app is still running because when I click the banner ad again and close out of it again the game returns to normal and the game had progressed while visually frozen. This is how the banner is initialized in my view controller class (the iAD delegate):
self.canDisplayBannerAds = YES;
CGRect bannerFrame = CGRectMake(0, 20, scene.size.width, 50);
banner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
banner.delegate = self;
banner.frame = bannerFrame;
[banner setAlpha:0];
[self.view addSubview:banner];
And these are the loading methods, also in the view controller class:
- (void) bannerViewDidLoadAd:(ADBannerView *) bannerM
{
NSLog(#"Ad Loaded");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[bannerM setAlpha:1];
[UIView commitAnimations];
}
- (void) bannerView:(ADBannerView *)bannerM didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Ad Failed");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[bannerM setAlpha:0];
[UIView commitAnimations];
}
I don't really understand the problem or why it is happening... Any help would be appreciated!
Thanks,
StrongJoshua
EDIT Here are the two methods that are called when the banner ads open and close:
- (BOOL) bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
if(playing)
{
NSLog(#"Ad Pause");
SKView *v = (SKView *)self.view;
NSLog(#"2");
SKScene *s = (SKScene *)v.scene;
NSLog(#"3");
WBPlayScene *p = (WBPlayScene *) s;
NSLog(#"4");
[p.logic pause:YES];
NSLog(#"Done");
}
return YES;
}
- (void) bannerViewActionDidFinish:(ADBannerView *)banner
{
if(playing)
{
NSLog(#"Ad Unpause");
[((WBPlayScene *)((SKView *)self.view).scene).logic pause:NO];
}
}
FIXED
The reason for all those NSLogs is because the game crashes when I try to pause it. The game crashes after "2" is reached, so at SKScene *s = (SKScene *)v.scene;. It gives the error [UIView scene]: unrecognized selector sent to instance and I don't understand why...
Solution: To fix this side issue I changed self.view to self.originalContentView and it got the SKView instead of the ad banner's view.
Thanks very much for your help!
SOLVED: I had to remove the call to enable ad display self.canDisplayBannerAds because it interfered with my self-created banner.
I want to fill the iAd space with AdMob advertisements when iAd is unavailable and was wondering if this was the right way to code it to do so. Every time I've run my simulator it has displayed iAd, and when it doesn't it shows a white strip, so I'm wondering if I've coded it wrong. Could someone help me out, and fix the code if necessary, or add suggestions. Thanks.
//iAd Advertising
#pragma mark iAd Delegate Methods
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
advertisement.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
//bannerView_.hidden = YES;
} // if there is an internet connection, load the iAd with a 1 second fade in effect
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
advertisement.hidden = YES;
bannerView_.hidden = NO;
bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 50)];
bannerView_.adUnitID = #"//pubname";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
#end
Your code is right. I'm guessing the error is in the storyboard. On the storyboard click the iAd and make sure the Alpha is set to 0. That should solve it.
Sorry for the late answer.
My advertisement banner is replaced with a white banner when there is no content to display. Is there any reason for this based on the code provided? Also, is there anyway to properly supplement the banner with AdMob when iAd is unavailable?
//iAd Advertising
#pragma mark iAd Delegate Methods
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
advertisement.hidden = YES;
}
I had tried this as far as supplementing it with Google AdMob:
#pragma mark iAd Delegate Methods
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
advertisement.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
bannerView_.hidden = YES;
} // if there is an internet connection, load the iAd with a 1 second fade in effect
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
//MAKE SURE THIS IS RIGHT OR FIGURE OUT HOW TO MAKE IT RIGHT
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
advertisement.hidden = YES;
//2
bannerView_.hidden = NO;
bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 50)];
bannerView_.adUnitID = #"//ca-app-pub-";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
Was I wrong to make outlets of the bannerviews and have them hidden or shown? It doesn't work, it always only shows one of the advertisements, and as stated before, when iAd isn't there it only shows a white banner with nothing in it, which is intrusive and not cosmetic for the app's purpose.
Based on this, what have I done wrong? For both cases that is, why does the iAd show a white banner, and why does the AdMob not supplement itself.
In StoryBoard, set your banner to hidden.
In your viewController (the one define as delegate for the banner), put this code :
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[banner setHidden:false];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Error : %#",error.description);
[banner setHidden:true];
}
If you set the alpha to 0 in storyboards, this will allow your code you've already used to work. Had the same problem.
It looks like in didFailToReceiveAdWithError: you should be animating the banner alpha to zero but you're actually animating it to one.
i'm developing dict for iOS, and try to use iAd for monetization. I done step by step with examples, except creating ad view, but ad doesn't show correct.
my code:
- (void)viewDidLoad
{
adView.frame = CGRectOffset(adView.frame, 0, -50); //don't work
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible){
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50); //works well
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible){
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I work with storyboard, using autolayout, tried to set
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Nothing helped.
Is it showing in the wrong position, or just not showing the ad when built in release mode? If it is in the wrong position, don't use the autoresizingMask and use the autolayout constraints in the storyboard instead. If it is not showing up after building in release/submitting to app store, then you most likely still need to register for the iAd network through iTunesConnect.
It looks like you are using iOS 7. There is a really easy way to add iAds if you don't mind it showing up on the bottom of the view:
#import <iAd/iAd.h>
yourViewController.canDisplayBannerAds = YES;
You do not need to implement any other show/hide methods if you use this property. Apple's WWDC 2013 video titled "iAd Integration and Best Practices" explains this in detail:
https://developer.apple.com/wwdc/videos/