Aligning an AdMob app in iOS app

Discussion in 'iOS Programming' started by gwelmarten, Oct 7, 2011.

  1. gwelmarten macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #1
    Hi

    I am trying to implement AdMob Ads into my iOS app. I've having trouble however, as the two photos will show the app working in both landscape and portrait mode. In portrait, the advert is aligned fine, however when in landscape the advert sticks to the left. I was this advert centred, and this becomes a bigger problem when I add them to the iPad. Please see screenshots attached for what is happening.

    My code in SafariViewController.h is:

    Code:
    ...
    
    @interface SafariViewController : UIViewController {
    	
        GADBannerView *bannerView_;
    }
    @end
    
    And then I have tried two bits of code in my SafariViewController.m:

    Code:
        // Create a view of the standard size at the bottom of the screen.
        bannerView_ = [[GADBannerView alloc]
                       initWithFrame:CGRectMake(0.0,
                                                self.view.frame.size.height -
                                                GAD_SIZE_320x50.height,
                                                GAD_SIZE_320x50.width,
                                                GAD_SIZE_320x50.height)];
        
        // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
        bannerView_.adUnitID = @"a14e8cb1e3bff49";
        
        // 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;
        [self.view addSubview:bannerView_];
        
        // Initiate a generic request to load it with an ad.
        [bannerView_ loadRequest:[GADRequest request]];
    AND

    Code:
        // 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 = @"a14e8cb1e3bff49";
    
       // Place the ad view onto the screen.
       [self.view addSubview:adView];
       [adView release];
    
       // Request an ad without any additional targeting information.
       [adView loadRequest:nil];
    Basically I am looking for a method of aligning my advert block in the middle of the screen, whether in portrait or landscape orientation. I was wondering if I could like this somehow to a view which I could then position correctly in the interface builder?

    Any help much appreciated - I'm new to objective C so basic rather than advance if possible please.

    Thanks in advance

    Sam
     

    Attached Files:

  2. lefooey macrumors member

    Joined:
    Dec 26, 2009
    Location:
    Spokane, WA
    #2
    You're setting the origin of the adFrame's frame to the upper left-hand corner. Adjust adFrame.frame.origin.x and adFrame.frame.origin.y appropriately.
     
  3. gwelmarten thread starter macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #3
    Hi

    Thanks for the prompt reply. I'm not so sure how to do this - would it be possible for you to tell me what lines of code in my example I would change, and roughly what I will change them to (just a bit more info please - I don't want to ask lots of your time to fix my problems). It would be much appreciated - I've googled but don't understand what to do with your pointers.

    Thanks:

    Sam
     
  4. gwelmarten, Oct 8, 2011
    Last edited by a moderator: Oct 8, 2011

    gwelmarten thread starter macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #4
    Displaying content from a separate XIB in a view

    Hi
    I am trying to get AdMob adverts to display correctly in my app, following the instructions at http://code.google.com/mobile/ads/docs/ios/fundamentals.html.

    I'm trying to put the admob adverts into their own view, with their own XIb, view controller.h/m. I've got this working, but now want to implement it into my app. Is there a way to display the contents of a XIB in a view at the top of my app, say only 50 pixels high? The reason for this is that then I can drag the adverts about in interface builder in the view.

    Any help would be much appreciated - please keep it relatively basic - I'm still not good with Objective C.

    Thanks in advance:D

    Sam
     

Share This Page