Xcode 4.4 with admod

797 views Asked by At

I would like to add admob at my ios application.

I have follow that tutorial :

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en#ios

But even with sample project or add source code at my ios project with that code, i have one error :

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADBannerView private]: unrecognized selector sent to instance 0x1727d0'

With that source code :

ViewController.h

#import <UIKit/UIKit.h>
#import "GADBannerView.h"

@interface ViewController : UIViewController{
    GADBannerView *bannerView_;
}

@end

And

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // 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 = @"MYID";

    // 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]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

@end
2

There are 2 answers

0
David On BEST ANSWER

I ran into a smilar problem. I fixed it by using the -all_load linker flag.

Here is what you need.

https://developers.google.com/mobile-ads-sdk/docs/#incorporating

0
MobileDevMaster On

If you've already add -all_load and it's still not working:

  1. Close XCode make sure you close it properly.
  2. Reopen XCode.
  3. Clean the project.
  4. Build.

Good Luck :)