51
votes

I have installed the AdMob SDK 6.2.0 (Xcode 4.5 (4G182) and I am testing on an iPhone 4S and the simulator). I followed the tutorial and just want to get AdMob showing a banner once. But it crashes on the last line:

self.bannerView = [[GADBannerView alloc]
               initWithFrame:CGRectMake(0.0,
                                        self.view.frame.size.height -
                                        GAD_SIZE_320x50.height,
                                        GAD_SIZE_320x50.width,
                                        GAD_SIZE_320x50.height)];

self.bannerView.delegate = self;
self.bannerView.adUnitID = @"xREMOVEDBYMEx";
self.bannerView.rootViewController = self;
[self.view addSubview:self.bannerView];
GADRequest * request = [GADRequest request];
request.testing = YES;
[self.bannerView loadRequest:request];

The crash is

2012-09-28 09:03:58.268 NewProject[1467:c07] -[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0x95c17d0 2012-09-28 09:03:58.276 NewProject[1467:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0x95c17d0'

This looks like a bug in the library to me but I think thats very unlikely. Any thoughts?

EDIT: The exact same code works in the example projects. Is there something I can do wrong with my project file that would result in that error?

4

4 Answers

171
votes

You need to add -ObjC to the Other Linker Flags of your application target's build setting:

  1. Click the blue top-level project icon in XCode
  2. Choose your target and go to Build Settings
  3. Under Other Linker Flags add -ObjC for both Release and Debug

Source: https://developers.google.com/mobile-ads-sdk/docs/admob/mediation#ios-linker

Also be sure to do a clean and rebuild

4
votes

Best solution for me is use -force_load flag instead -ObjC enter image description here

3
votes

If you guys are still having trouble, make sure it's -ObjC and not -Objc. Geez, spent weeks trying to figure out why.

0
votes

For those of you who tried adding the Obj-c linker flag and still got the same "unrecognized selector sent to instance" error when trying to load an ad I found a fix. This is for the newest XCode (version 8.1).

For reference:

  • I added Google AdMob using cocoapods.
  • I used storyboard to make an outlet connection to my viewcontroller and GADBannerView was NOT available as a class so I wrote it in like most people did.
  • On one of the stackoverflow answers that I saw the custom class for the bannerview was set to GADBannerView, which I assume would happen automatically if it was an option in the dropdown list when you added the outlet. For me it wasn't since I had to type it in myself.

No custom class specified screengrab

Looking at the dropdown I saw that GADBannerView was available as an option and selected it.

GADBannerView class available

After selecting it, the app ran without a hitch, no need to add the linker flag (mine was blank by default) or anything.

Hope this helps someone else!