Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 122

SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
03/21/16 04:46 AM (8 years ago)

Save Time and filesize adMob in the BT_viewController

I just added 'adMob' into my latest iOS project, using the instructions found after a few searches in the forums, and noticed everyone was putting the code in the plugin... https://www.buzztouch.com/forum/thread.php?tid=BE13504D728DD566D5123B2 Therefore, if they have 20 plugins, they performed this procedure 20 times. At first I did it this way, but kept thinking that it was all just a subclass of BT_viewController. So I cut out all the code from my project, and placed the code in my BT_viewController. Now the advertisements are on all of my screens. Just a thought for your next project, If you're going to go that route... in BT_viewController.h add: @import GoogleMobileAds; // up top; near your #imports and @property (nonatomic, retain) GADBannerView *googleAdBannerView; // with your properties. in BT_viewController.m add: #define MY_BANNER_UNIT_ID @"ca-app-pub-XXXXXXXXXXX" // up top; near your #imports and @synthesize googleAdBannerView; in BT_viewController/viewDidLoad: int screenHeight = self.view.bounds.size.height; int screenWidth = self.view.bounds.size.width; guamflights_appDelegate *appDelegate = (guamflights_appDelegate *)[[UIApplication sharedApplication] delegate]; if([appDelegate.rootDevice isIPad]){ googleAdBannerView = [[GADBannerView alloc] initWithFrame:CGRectMake((screenWidth / 2) - (GAD_SIZE_728x90.width / 2), screenHeight - (GAD_SIZE_728x90.height + 2), // - 88, GAD_SIZE_728x90.width, //(self.view.frame.size.width /2) - (GAD_SIZE_728x90.width / 2), GAD_SIZE_728x90.height)]; } else { googleAdBannerView = [[GADBannerView alloc] initWithFrame:CGRectMake((screenWidth / 2) - (GAD_SIZE_320x50.width / 2), self.view.bounds.size.height - (GAD_SIZE_320x50.height + 2), GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)]; } googleAdBannerView.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth); googleAdBannerView.backgroundColor = [UIColor clearColor]; googleAdBannerView.adUnitID = MY_BANNER_UNIT_ID; googleAdBannerView.rootViewController = self; GADRequest *myGADRequest = [GADRequest request]; [myGADRequest tagForChildDirectedTreatment:NO]; if (![appDelegate.rootDevice.deviceLatitude isEqualToString:@"0"]) { float gadLat = [appDelegate.rootDevice.deviceLatitude doubleValue]; float gadLng = [appDelegate.rootDevice.deviceLongitude doubleValue]; [myGADRequest setLocationWithLatitude:gadLat longitude:gadLng accuracy:appDelegate.rootLocationMonitor.locationManager.location.horizontalAccuracy]; } myGADRequest.testDevices = @[ @"546570c325268325abe58b4363689005", @"c130c74e36cb96e48456c14a8cc9d9f8", kGADSimulatorID ]; [self.googleAdBannerView loadRequest:myGADRequest]; [self.view addSubview:googleAdBannerView]; [self.view bringSubviewToFront:googleAdBannerView]; [BT_debugger showIt:self message:[NSString stringWithFormat:@"Google Mobile Ads SDK version: %@", [GADRequest sdkVersion]]]; Make sure your bannerUnitID is correct. Make sure your test device identification is correct. Otherwise, it should be relatively smooth sailing. Cheers! -- Smug Edit: if you want to get fancy, instead of placing this in 'viewDidLoad', you can alternatively place it in the BT_viewController "createAdBanner" method, and then use the "includeAds" json property of each individual plugin (if available) or just 'hotwire' (or disable) the code in the plugin.
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
03/21/16 06:48 AM (8 years ago)
Great, many thanks for this piece of code!
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/21/16 09:02 AM (8 years ago)
Did you try the smart banner at all?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/21/16 12:59 PM (8 years ago)
I'm not smart enough. (Smart banner? what smart banner?) Cheers! -- Smug Edit: I may try a 'smart banner' later... for the moment, I'm just happy to get the regular one to work, lol!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
03/22/16 10:24 AM (8 years ago)
Nice hotwire smug ;) Thanks
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/09/16 01:10 PM (8 years ago)
Also, now with Apple Ads gone its best to do the latter. I have added the code to directly to the BT_viewcontroller ad view section. //createAdBannerView Thanks Smug, makes things so much easier.
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/09/16 03:01 PM (8 years ago)
Also, now with Apple Ads gone its best to do the latter. I have added the code to directly to the BT_viewcontroller ad view section. //createAdBannerView Thanks Smug, makes things so much easier.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.