AdMob error using [GADObjectPrivate changeState:]: unrecognized selector

I installed AdMob SDK 6.2.0 (Xcode 4.5 (4G182) and I am testing iPhone 4S and simulator). I followed the tutorial and just want AdMob to show the banner once. But it falls 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]; 

Crash

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] * Application termination from due to an unmapped "NSInvalidArgumentException" exception, reason: '- [GADObjectPrivate changeState:]: unrecognized selector sent to instance 0x95c17d0'

It looks like a bug in the library for me, but I think it is very unlikely. Any thoughts?

EDIT: The same code works in sample projects. Is there something I can do with the project file that will lead to this error?

+51
objective-c iphone admob
Sep 28 '12 at 7:12
source share
4 answers

You need to add -ObjC to the other linker flags of your application build target value:

  • Click the blue top-level project icon in Xcode
  • Choose your target and go to build settings
  • Under Other linker flags, add -ObjC to release and debug

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

Also remember to clean and rebuild

+171
Sep 28 '12 at 11:19
source share

The best solution for me is to use the -force_load flag instead of -ObjC enter image description here

+4
Aug 30 '13 at 18:01
source share

If you still have problems, make sure it is -ObjC and not -Objc. Geez spent weeks trying to figure out why.

+3
Aug 14 '13 at 22:03
source share

For those of you who tried to add the Obj-c linker flag and still got the same “unrecognized selector sent to instance” error while trying to load the ad, I found a fix. This is for the latest Xcode (version 8.1).

For reference:

  • I added Google AdMob using cocoapods.
  • I used a storyboard to establish an output connection with my view controller, and GADBannerView was NOT available as a class, so I wrote it like most people did.
  • In one stackoverflow answer that I saw, the custom class for bannerview was set to GADBannerView, which I assume would happen automatically if it were an option in the drop-down list when you added the output. This was not for me, since I had to type it in myself.

There is no special class specified by screengrab

Looking at the drop-down list, I saw that GADBannerView is available as an option and selected it.

GADBannerView Class Available

After selecting it, the application starts without a hitch, you do not need to add the linker flag (mine was empty by default) or anything else.

Hope this helps someone else!

0
Nov 22 '16 at 1:44
source share



All Articles