UITabBarControllerなアプリの場合の広告(admob)の置き方 2012/05/24

AdMobです。 タブなアプリケーションでタブを切り替えるたびに広告をロードしてしまうのがいやだなーと思っていました。



参考
アプリ開発:UITabBarControllerへの効果的な広告の貼り方 | JOHN DOE
ApplicationDelegateのdidFinishLaunchingWithOptionsでのっけるのがいい感じでした。

rootViewControllerがUITabBarControllerなので素直にwindowから取得するという方法です。

僕の現在のコードはこんな感じです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // *UITabBarControllerを取得する UITabBarController *tabBarController = (UITabBarController*)self.window.rootViewController; _gadBannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, tabBarController.view.frame.size.height - GAD_SIZE_320x50.height - 49, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)]; // Specify the ad's "unit identifier." This is your AdMob Publisher ID. _gadBannerView.adUnitID = @""; // Let the runtime know which UIViewController to restore after taking // the user wherever the ad goes and add it to the view hierarchy. _gadBannerView.rootViewController = tabBarController; [tabBarController.view addSubview:_gadBannerView]; // Initiate a generic request to load it with an ad. [_gadBannerView loadRequest:[GADRequest request]]; return YES; }

: