From e12567e57fd4ed81783e2f7087422965855cc51d Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 1 Jun 2017 10:22:15 +0100 Subject: [PATCH] [admob][android] Add initialize method + documentation --- .../invertase/firebase/admob/RNFirebaseAdMob.java | 10 ++++++---- docs/modules/admob.md | 13 +++++++++++-- lib/modules/admob/AdMobComponent.js | 1 - lib/modules/admob/index.js | 11 +++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java b/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java index 920929e2..2e3c6a60 100644 --- a/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java +++ b/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java @@ -7,13 +7,11 @@ import android.util.Log; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.google.android.gms.ads.AdRequest; -import io.invertase.firebase.Utils; +import com.google.android.gms.ads.MobileAds; import java.util.HashMap; -import java.util.List; import java.util.Map; @@ -31,7 +29,6 @@ public class RNFirebaseAdMob extends ReactContextBaseJavaModule { private HashMap interstitials = new HashMap<>(); private HashMap rewardedVideos = new HashMap<>(); - private HashMap nativeExpressAds = new HashMap<>(); public RNFirebaseAdMob(ReactApplicationContext reactContext) { super(reactContext); @@ -43,6 +40,11 @@ public class RNFirebaseAdMob extends ReactContextBaseJavaModule { return TAG; } + @ReactMethod + public void initialize(String appId) { + MobileAds.initialize(this.getContext(), appId); + } + @ReactMethod public void interstitialLoadAd(String adUnit, ReadableMap request) { RNFirebaseAdmobInterstitial interstitial = getOrCreateInterstitial(adUnit); diff --git a/docs/modules/admob.md b/docs/modules/admob.md index 58009da1..b5b27cf4 100644 --- a/docs/modules/admob.md +++ b/docs/modules/admob.md @@ -1,8 +1,17 @@ # AdMob -The admob allows you to display adverts in your app, using your account from [AdMob by Google](https://www.google.co.uk/admob/). +The admob allows you to display adverts in your app, using your account from [AdMob by Google](https://www.google.co.uk/admob/). RNFirebase allows you to display Banners, Interstitials, NativeExpress Ads & Rewarded Videos. -RNFirebase allows you to display Banners, Interstitials, NativeExpress Ads & Rewarded Videos. +## Initialize + +Before using any AdMob feature, ensure you call the initialize method. This only needs to be done once per the apps lifecycle. +Initialize takes your AdMob App ID, where you can find on your AdMob dashboard. + +> For testing purposes, you can use AdMobs test app ID "ca-app-pub-3940256099942544~3347511713". + +```js +firebase.admob().initialize("ca-app-pub-3940256099942544~3347511713"); +``` ## API diff --git a/lib/modules/admob/AdMobComponent.js b/lib/modules/admob/AdMobComponent.js index 9216f10d..456bda5f 100644 --- a/lib/modules/admob/AdMobComponent.js +++ b/lib/modules/admob/AdMobComponent.js @@ -61,7 +61,6 @@ class AdMobComponent extends React.Component { * @param nativeEvent */ onBannerEvent = ({ nativeEvent }) => { - console.log(nativeEvent) if (this.props[nativeEvent.type]) { if (nativeEvent.type === 'onAdFailedToLoad') { const { code, message } = nativeEvent.payload; diff --git a/lib/modules/admob/index.js b/lib/modules/admob/index.js index aa71cb89..62085258 100644 --- a/lib/modules/admob/index.js +++ b/lib/modules/admob/index.js @@ -20,6 +20,7 @@ export default class Admob extends Base { return nativeSDKMissing('admob'); } + this._initialized = false; FirebaseAdMobEvt.addListener('interstitial_event', this._onInterstitialEvent.bind(this)); FirebaseAdMobEvt.addListener('rewarded_video_event', this._onRewardedVideoEvent.bind(this)); } @@ -46,6 +47,16 @@ export default class Admob extends Base { this.emit(jsEventType, event); } + initialize(appId: string) { + if (this._initialized) { + this.log.warn('AdMob has already been initialized!'); + return; + } + + this._initialized = true; + return FirebaseAdMob.initialize(appId); + } + interstitial(adUnit: string) { return new Interstitial(this, adUnit); }