Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Now I ve finally integrated admob and iAd into one application, but I would like to do, if iAd doesn't enable for example in a country, admob comes up. If iAd enable, and receive ads, admob doesn't show on. How can I do this?

Here is my full code: .h

#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import <iAd/iAd.h>

@class GADBannerView, GADRequest;

@interface ViewController : UIViewController <GADBannerViewDelegate, ADBannerViewDelegate>{
    GADBannerView *bannerView_;
}
@property(nonatomic,strong)GADBannerView *bannerView;

-(GADRequest *)createRequest;
@end

.m:

#import "ViewController.h"
#import "GADBannerView.h"
#import "GADRequest.h"
#import "source.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize bannerView = bannerView_;
-(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];
}
- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.bannerView = [[GADBannerView alloc]initWithFrame:CGRectMake(0.0, self.view.frame.size.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];

    self.bannerView.adUnitID = MyAdUnitID;
    self.bannerView.delegate = self;
    [self.bannerView setRootViewController:self];
    [self.view addSubview:self.bannerView];
    [self.bannerView loadRequest:[self createRequest]];
}

#pragma mark Request Generation

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

    return request;
}

#pragma mark GADBannerViewDelegate impl

-(void)adViewDidReceiveAd:(GADBannerView *)adView{
    NSLog(@"Received ad");

    [UIView animateWithDuration:1.0 animations:^{
        adView.frame = CGRectMake(0.0, self.view.frame.size.height - adView.frame.size.height, adView.frame.size.width, adView.frame.size.height);
    }];

}
-(void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error{
    NSLog(@"Failed to received ad with error : %@",[error localizedFailureReason]);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.