Skip to content

Instantly share code, notes, and snippets.

@digitalasia
Created January 14, 2014 09:57
Show Gist options
  • Save digitalasia/8415949 to your computer and use it in GitHub Desktop.
Save digitalasia/8415949 to your computer and use it in GitHub Desktop.
iads and admobs
#pragma mark iADs and Admob
-(void) addAdMob
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier". This is your AdMob Publisher ID.
bannerView_.adUnitID = @"";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = screenRect.size.height;
bannerView_.frame = CGRectMake(0, screenHeight - 50, 320, 50);
// bannerView_.layer.borderWidth = 2.0f;
// bannerView_.layer.borderColor = [UIColor blackColor].CGColor;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
// if (!self.bannerIsVisible)
// {
// [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// // banner is invisible now and moved out of the screen on 50 px
// banner.frame = CGRectOffset(banner.frame, 0, 50);
// [UIView commitAnimations];
// self.bannerIsVisible = YES;
// }
NSLog(@"Ads Loaded");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
// 1
[adView removeFromSuperview];
// 2
[self addAdMob];
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
[bannerView_ removeFromSuperview];
[self addIAds];
}
-(void) addIAds
{
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.delegate = self;
[self.view addSubview:adView];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment