I have correctly implemented a shared iAd banner in the appDelegate and in certain views(which are adbanner delegates) it appears correctly. How ever in the views where I dont show the banner (so they are not adbanner delegates) when the appdelegate fails to retrieve a Banner since there is no current delegate and no current didFailToRecieveAdWithError method the console shows an error saying that efectively there is no method to recieve the error. Do i need to make the appDelegate also the AdBannerDelegate and put those methods inside?
In appDelegate:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
_UIiAD = [[ADBannerView alloc]init];
return YES;
}
in ViewController where I want a Banner:
- (CrystalAppDelegate *)appDelegate
{
return (CrystalAppDelegate *)[[UIApplication sharedApplication]delegate];
}
- (void)viewWillAppear:(BOOL)animated
{
_UIiAD = [[self appDelegate] UIiAD];
_UIiAD.delegate = self;
[_UIiAD setFrame:CGRectMake(0, 518, 320, 50)];
[self.view addSubview:_UIiAD];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"Banner did Load");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Banner did not Load");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:0];
[UIView commitAnimations];
}
-(void)viewWillDisappear:(BOOL)animated
{
_UIiAD.delegate = nil;
_UIiAD = nil;
[_UIiAD removeFromSuperview];
}
Problem is when i am in a view that doesnt have a banner i dont have these methods so when the appDelegate doesnt retrieve a iAdBanner there is no method to revieve the error.
Related
I followed a youtube tutorial on how to implement shared iads banner in my app. I have 10 VC so this is why i choosed the shared iads via delegate. Whenever I launch the app (On device or simulator) the ad doesn't appear on the first view controller. If i switch to the 2nd VC, it will load and show correctly. Then if i decide to go to the 3rd VC or back to the 1st VC, the banner will be white and no ads will load (even if i wait or go to any other VC).
Maybe the tutorial i watched wasn't correctly written, i don't know to be honest. Here's the code used:
AppDelegate.h
#property (strong, nonatomic) ADBannerView *UIiAD;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_UIiAD = [[ADBannerView alloc] init];
return YES;
}
ViewController.h
#property (strong, nonatomic) ADBannerView *UIiAD;
ViewController.m
- (AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(void) viewWillAppear:(BOOL)animated{
_UIiAD = [[self appdelegate] UIiAD];
_UIiAD.delegate = self;
if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
[_UIiAD setFrame:CGRectMake(0,518,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 480)
{
[_UIiAD setFrame:CGRectMake(0,430,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 667)
{
[_UIiAD setFrame:CGRectMake(0,600,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 736)
{
[_UIiAD setFrame:CGRectMake(0,660,320,50)];
}
[self.view addSubview:_UIiAD];
}
-(void) viewWillDisappear:(BOOL)animated{
[_UIiAD removeFromSuperview];
_UIiAD.delegate = nil;
_UIiAD = nil;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(#"ads loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[_UIiAD setAlpha:1];
[UIView commitAnimations];
self.fullscreen = [[RevMobAds session] fullscreen];
self.fullscreen.delegate = self;
[self.fullscreen loadAd];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"ads not loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[_UIiAD setAlpha:0];
[UIView commitAnimations];
}
Conclusion
I tried adding a delay in the ViewWillAppear method but it did not work.
I placed the banner in the storyboard and made sure it was on 0 alpha.
No other answer on SO helped me so hopefully someone will be able to resolve this issue. Thanks!
To conclude my comments,
use storyboard auto layout to position the banner or use a placeholder to get the position of the later banner.
Remove the animations and replace them with .hidden=true and =false.
Set the adBanner to hidden in storyboard or at the point of your initialization.
I can't find the right solution to hide my iAd view when I press a button.
I am loding iAd view like this:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
It works perfect. But how would i hide my iAd view if I don't want to show one?
I was searching for answer here, but there was no direct answer.
If the user doesn't have internet connection the banner will be blank. It is required by apple for the banner to be hidden when internet connection is not availble.
Consider you are creating this way,
- (void)createAdBannerView {
Class classAdBannerView = NSClassFromString(#"ADBannerView");
if (classAdBannerView != nil) {
self.adBannerView = [[[classAdBannerView alloc]
initWithFrame:CGRectZero] autorelease];
[_adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:
ADBannerContentSizeIdentifier320x50,
ADBannerContentSizeIdentifier480x32, nil]];
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier480x32];
} else {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier320x50];
}
[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0,
-[self getBannerHeight])];
[_adBannerView setDelegate:self];
[self.view addSubview:_adBannerView];
}
}
call [self.adBannerView removeFromSuperview]; when and were you need to hide.
#Matiass21, write the below code here _bannerIsVisible is bool value and _adBanner is ADBannerView object.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
// If banner isn't part of view hierarchy, add it
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Failed to retrieve ad");
if (_bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}
Based on the tutorial at http://www.youtube.com/watch?v=u5XcVnHCQ0w , I implemented shared iAd banner view to show between header position of two tables. Two table controllers are under navigation controller. Banner view is showing in the first table, but it is not showing in the next table.
Same code I implemented in UItableViewControllers
- (AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 100.0;
}
-(void) viewWillAppear:(BOOL)animated{
_UIiAD = [[self appdelegate] UIiAD];
_UIiAD.delegate = self;
[_UIiAD setFrame:CGRectMake(0,21,320,50)];
[self.view addSubview:_UIiAD];
}
-(void) viewWillDisappear:(BOOL)animated{
_UIiAD.delegate = nil;
_UIiAD=nil;
[_UIiAD removeFromSuperview];
}
-(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];
}
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 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.