Need help integrating admobs into an app

Discussion in 'iOS Programming' started by bandecorp, Jan 23, 2012.

  1. bandecorp, Jan 23, 2012
    Last edited by a moderator: Jan 23, 2012

    bandecorp macrumors newbie

    Joined:
    Jan 23, 2012
    #1
    Code:
    //  FixMyBikeTOAppDelegate.h
    
    
    #import <UIKit/UIKit.h>
    
    #import "AdMobDelegateProtocol.h"
    
     
    @class RankViewController;
    
     
    @interface FixMyBikeTOAppDelegate : NSObject <UIApplicationDelegate,AdMobDelegate> {
    
    UIView *mainView;
    
        UIWindow *window;
    
    UINavigationController *nav;
    
    RankViewController *root; 
    
    }
    
     
    - (void) loadMainWindow;
    
     
    @property (nonatomic, retain) UIView *mainView;
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    
    @property (nonatomic, retain) UINavigationController *nav;
    
    @property (nonatomic, retain) RankViewController *root;
    
     
     
    @end
    
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    //  FixMyBikeTOAppDelegate.m
    
    
    
    #import <CoreLocation/CoreLocation.h>
    
    #import "FixMyBikeTOAppDelegate.h"
    
    #import "RankViewController.h"
    
    #import "BikeStoresTableViewController.h"
    
    #import "AdMobDelegateProtocol.h"
    
    #import "AdMobView.h"
    
    #import "AdViewController.h"
    
     
    @implementation FixMyBikeTOAppDelegate
    
     
    @synthesize window, nav, root, mainView;
    
     
    - (void)dealloc {
    
    [nav release];
    
    [mainView release];
    
        [window release];
    
        [super dealloc];
    
    }
    
     
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
     
    RankViewController *rootController = [[RankViewController alloc] init];
    
    self.root = rootController;
    
    [rootController release];
    
     
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:root];
    
    [[navController navigationBar] setBarStyle:UIBarStyleBlackOpaque];
    
    self.nav = navController;
    
    [navController release];
    
     
    [window setBackgroundColor:[UIColor blackColor]];
    
     
    mainView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    
    [mainView clipsToBounds];
    
     
    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smiletemp.png"]];
    
    [mainView addSubview:background];
    
    [window addSubview:mainView];
    
    // [window addSubview:background];
    
    [background release];
    
     
    //AdMobView *ad = [AdMobView requestAdWithDelegate:self]; // start a new ad request
    
    //ad.frame = CGRectMake(0, 432, 320, 48); // set the frame, in this case at the bottom of the screen
    
    //[window addSubview:ad]; // attach the ad to the view hierarchy; self.window is responsible for retaining the ad
    
    /* 
    
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(10,10,50,50)];
    
    [name setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:24]];
    
    [name setText:@"test"];
    
    [window addSubview:name];
    
    [name release];
    
    */ 
    
    [self performSelector:@selector(loadMainWindow) withObject:nil afterDelay:3.0];
    
    // [mainView addSubview:self.nav.view];
    
        [window makeKeyAndVisible];
    
     
    }
    
     
    - (void)loadMainWindow {
    
    [[mainView.subviews objectAtIndex:0] removeFromSuperview];
    
    [mainView addSubview:self.nav.view];
    
    }
    
     
     
    - (void)applicationWillTerminate:(UIApplication *)application {
    
     
    // save the preferences and current state...
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    [userDefaults synchronize];
    
     
    }
    
     
     
     
    #pragma mark -
    
    #pragma mark AdMobDelegate methods
    
     
    - (NSString *)publisherId {
    
    return @"a14b4d0e8fb6036"; // this should be prefilled; if not, get it from [url]www.admob.com[/url]
    
    }
    
     
    - (BOOL)useTestAd; 
    
    { 
    
    return NO; 
    
    }
    
     
    - (UIColor *)adBackgroundColor {
    
    return [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1]; // this should be prefilled; if not, provide a UIColor
    
    }
    
     
    - (UIColor *)primaryTextColor {
    
    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor
    
    }
    
     
    - (UIColor *)secondaryTextColor {
    
    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor
    
    }
    
     
    - (BOOL)mayAskForLocation {
    
    return YES; // this should be prefilled; if not, see AdMobProtocolDelegate.h for instructions
    
    }
    
    @end
    
    
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    // The view that displays banner ads.  A minimum implementation to get an ad
    
    // from within a UIViewController class is:
    
    //
    
    //   // Place an ad at the top of the screen of an iPhone/iPod Touch.
    
    //   CGRect adFrame = CGRectZero;
    
    //   adFrame.size = GAD_SIZE_320x50;
    
    //
    
    //   // Create and setup the ad view.
    
    //   GADBannerView *adView = [[GADBannerView alloc] initWithFrame:adFrame];
    
    //   adView.rootViewController = self;
    
    //   adView.adUnitID = @"ID created when registering my app";
    
    //
    
    //   // Place the ad view onto the screen.
    
    //   [self.view addSubview:adView];
    
    //   [adView release];
    
    //
    
    //   // Request an ad without any additional targeting information.
    
    //   [adView loadRequest:nil];

    I'm trying to do this (new Admob code right above) in the original code, but there seems to be an incompatiblity. The new version uses UIViewController, but the older version of Admobs uses UIView to display the ad. Is there a way to convert UIViewController to UIView?


    The first two files shown above are where the older version of Admobs is implemented in the original code.


    Thanks in advance.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    The fact that you would ask this question shows that you don't understand the important difference between the two. I'd suggest you go learn more about how they differ.
     

Share This Page