Last active
March 31, 2016 19:33
-
-
Save darklight721/cc5c4828f7e440d12e28 to your computer and use it in GitHub Desktop.
Using AdMob in React Native [see my comment below for instructions]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So there's this sample repo already showing you how to add AdMob into your react native app.
But I found some issues using it. First, you can't call
AdMob.showBannerOnBottomOfTheView
incomponentDidMount
because therootViewController
wouldn't still be ready, and the AdMob needs it to display the ad. But you can fix this by putting a timeout before you callshowBannerOnBottomOfTheView
, but this is plain ugly.Secondly, the ad banner is attached to the root view, so once you've added it, it shows in all your scenes. So if you don't want it to show in one scene, you would call
removeBannerFromTheView
. Then add it back when the scene changes.And lastly, I wanted it to work like a component, this feels more natural in the react environment. So I would just add
<AdMobBanner />
into my view and poof! it shows in my view, and when that view is removed and so is the ad.So I took some time to learn the very basics of objective c and, finally, here's the result.
Usage:
AdMobBanner.h
,AdMobBanner.m
,AdMobBannerManager.h
,AdMobBannerManager.m
to your xcode project.AdMobBanner.js
to your react native codes directory.Sample app: