From c22fb3911fc5043ee995b599f662ea5e741634a6 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Tue, 27 Jun 2017 15:14:02 +0100 Subject: [PATCH] [admob] Add openDebugMenu support --- .../firebase/admob/RNFirebaseAdMob.java | 5 +++++ docs/modules/admob.md | 9 +++++++++ ios/RNFirebase/admob/RNFirebaseAdMob.m | 8 ++++++++ lib/modules/admob/index.js | 16 ++++++++++++++++ tests/src/tests/admob/admob.js | 1 + 5 files changed, 39 insertions(+) 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 2e3c6a60..0606b7f9 100644 --- a/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java +++ b/android/src/main/java/io/invertase/firebase/admob/RNFirebaseAdMob.java @@ -45,6 +45,11 @@ public class RNFirebaseAdMob extends ReactContextBaseJavaModule { MobileAds.initialize(this.getContext(), appId); } + @ReactMethod + public void openDebugMenu(String appId) { + MobileAds.openDebugMenu(getActivity(), 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 4e2cfdbc..403228e1 100644 --- a/docs/modules/admob.md +++ b/docs/modules/admob.md @@ -13,6 +13,15 @@ Initialize takes your AdMob App ID, where you can find on your AdMob dashboard. firebase.admob().initialize("ca-app-pub-3940256099942544~3347511713"); ``` +## Debugging + +Once initialized, you can debug ((Android)[https://developers.google.com/mobile-ads-sdk/docs/dfp/android/debug]/(iOS)[https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/debug]) +your ads using the debug menu. + +```js +firebase.admob().openDebugMenu(); +``` + ## API ### Banner diff --git a/ios/RNFirebase/admob/RNFirebaseAdMob.m b/ios/RNFirebase/admob/RNFirebaseAdMob.m index d17add89..398f38fd 100644 --- a/ios/RNFirebase/admob/RNFirebaseAdMob.m +++ b/ios/RNFirebase/admob/RNFirebaseAdMob.m @@ -32,6 +32,14 @@ RCT_EXPORT_METHOD(initialize: [GADMobileAds configureWithApplicationID:appId]; } +RCT_EXPORT_METHOD(openDebugMenu: + (NSString *) appId) { + GADDebugOptionsViewController *debugOptionsViewController = [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:appId]; + UIWindow* window = [UIApplication sharedApplication].keyWindow; + + [[window rootViewController] presentViewController:debugOptionsViewController animated:YES completion:nil]; +} + RCT_EXPORT_METHOD(interstitialLoadAd: (NSString *) adUnit request: diff --git a/lib/modules/admob/index.js b/lib/modules/admob/index.js index 00c13957..60cf667b 100644 --- a/lib/modules/admob/index.js +++ b/lib/modules/admob/index.js @@ -21,6 +21,7 @@ export default class Admob extends Base { } this._initialized = false; + this._appId = null; FirebaseAdMobEvt.addListener('interstitial_event', this._onInterstitialEvent.bind(this)); FirebaseAdMobEvt.addListener('rewarded_video_event', this._onRewardedVideoEvent.bind(this)); } @@ -54,9 +55,20 @@ export default class Admob extends Base { } this._initialized = true; + this._appId = appId; return FirebaseAdMob.initialize(appId); } + openDebugMenu() { + if (!this._initialized) { + this.log.warn('AdMob needs to be initialized before opening the dev menu!'); + return; + } + + this.log.info('Opening debug menu'); + return FirebaseAdMob.openDebugMenu(this._appId); + } + interstitial(adUnit: string) { return new Interstitial(this, adUnit); } @@ -68,6 +80,10 @@ export default class Admob extends Base { static get statics() { return statics; } + + get namespace(): string { + return 'firebase:admob'; + } } export const statics = { diff --git a/tests/src/tests/admob/admob.js b/tests/src/tests/admob/admob.js index 356fcf4a..e509a726 100644 --- a/tests/src/tests/admob/admob.js +++ b/tests/src/tests/admob/admob.js @@ -22,6 +22,7 @@ export default function addTests({ before, fdescribe, describe, it, firebase }) const admob = firebase.native.admob(); admob.should.have.property('initialize').and.be.a.Function(); + admob.should.have.property('openDebugMenu').and.be.a.Function(); admob.should.have.property('interstitial').and.be.a.Function(); admob.should.have.property('rewarded').and.be.a.Function(); resolve();