Created
January 14, 2014 09:57
-
-
Save digitalasia/8415949 to your computer and use it in GitHub Desktop.
iads and admobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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