jbcarpen
jbcarpen

Reputation: 327

Google admob GADBannerView Unrecognized Selector

After including the GoogleMobileAdvertising.framework in my project, and ensuring that it is found by the search paths, the following line of code still causes an unrecognized selector error.

GADBannerView* gadBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];

Yes, I already have the -ObjC linker flag set. Yes, I have included all the other required frameworks. No, this is not a duplicate question. There is a similar question already posted, but that one was a case of a missing -ObjC flag. This one quite clearly isn't, as that flag is present.

If I split the allocation and initialization onto separate lines. e.g.

GADBannerView* gadBannerView = [GADBannerView alloc];
[gadBannerView initWithAdSize:kGADAdSizeSmartBannerLandscape];

Then the error occurs on the second line, the initWithAdSize.

The error is

[UIApplication window]: unrecognized selector sent to instance 0x14e888b0

Which doesn't make much sense. Why is the initWithAdSize even calling on "window" as a selector? The UIApplicationDelegate protocol lists it as a property.

@property (nullable, nonatomic, strong) UIWindow *window NS_AVAILABLE_IOS(5_0);

Even so, the class implementing UIApplicationDelegate in this case does have that property. I could maybe understand the error if it was

[UIApplication setWindow]: unrecognized selector

or

[UIApplication getWindow]: unrecognized selector

But it isn't.

Upvotes: 0

Views: 449

Answers (1)

jbcarpen
jbcarpen

Reputation: 327

Ok, turns out the answer was in a child class of that delegate. It had "window" implemented as a member UIWindow* instead of as a property. So when the AdMob library tried to call the getter on that property, it wasn't there. Fixing it to implement it correctly as a property (and then fixing everything else in that class that suddenly won't compile because it's trying to access the property as a member) fixes the Unrecognized Selector error.

I will admit to a certain degree of satisfaction that the delegate in question was not my code.

Upvotes: 1

Related Questions