My app has been accepted for iAds advertising network, but after I download the app, I do not see the banner ad appears and I have to wait one week but still not see. I don't know if the app itself is faulty or not, here's the code I've used.
ViewController.h
#import <iAd/iAd.h>
#interface ViewController : UIViewController <ADBannerViewDelegate>
ViewController.m
#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:0];
[UIView commitAnimations];
}
Related
I have set up iAds for my app, but for whatever reason, they only appear on the iphone 4 inch and not the 3.5 inch. First, I thought it had something to do with the Auto Layout, so I made sure the BannerView appeared in both screen sizes. After doing so, I ran and still would not work.
Here is the code I used to tell the bannerView what to do. This is in the ViewController.m file.
#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:0];
[UIView commitAnimations];
}
Also, this is being done in Spritekit if that matters.
Thanks for helping, and I'm pretty new to coding so something that may seem obvious, I might have easily not noticed.
You cannot animate the alpha of an object. Alternatively, you should be modifying it's transparency via it's opacity:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 1.0f;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 0.0f;
}];
}
I have implemented the following code:
-(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:0];
[UIView commitAnimations];
}
And published the app to the app store. Ads are not showing up in the app store app nor am I getting any information in iTunes Connect when I go to view iAd information. Is this code right and the only code I have to put? In the storyboard, I have the iAd at the bottom of the screen connected to the delegate and I also have this in ViewController.h
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import <AudioToolbox/AudioToolbox.h>
#interface ViewController : UIViewController <ADBannerViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource> {
(Showing that I have imported the iAd Framework and have the ADBannerViewDelegate)
Hello I have an issue where my ads appear before they are even loaded.
I got this
#pragma mark iAd Delegate Methods
- (AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(void) viewWillAppear:(BOOL)animated{
//this part set alpha 0 does nothing
[_UIiAD setAlpha:0];
_UIiAD = [[self appdelegate] UIiAD];
_UIiAD.delegate = self;
[_UIiAD setFrame:CGRectMake(0,470,320,50)];
[self.view addSubview:_UIiAD];
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(#"ads loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"ads not loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:0];
[UIView commitAnimations];
}
I have tried to stick
[_UIiAD setAlpha:0];
In various parts of my code, but still same issue.
If your AdBannerView has been initialized outside of this snippet (presumably in AppDelegate from what you show in your viewWillAppear: code), it can still load ads even before it has a delegate.
Instead of programmatically adding the iAd banner as a subview after creating it somewhere else, have you tried adding it using Interface Builder and just using the code to hide/unhide based on whether or not it's received content.
my goal is to have my iAd show at the main menu screen(which I already accomplished) but when the user push a button to start the game I want the ad to go away and when the game ends the ad to reappear...I saw a lot of other similar questions but none had answers(searched for hours :/ ). also checked the documentation and couldn't find a logical solution, I'm also a newbie,thanks!
*update the code im working with .h file
-(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:0];
[UIView commitAnimations];
}
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.