From 92b3860230c7ba13dda93c1dced21ca74bc81a0a Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Tue, 4 Jul 2017 15:39:56 +0100 Subject: [PATCH] [admob][ios] Fix an issue whereby interstitials on iOS could not be reused with the same adUnit ID --- ios/RNFirebase/admob/RNFirebaseAdMob.m | 11 ++++++++--- lib/modules/admob/Interstitial.js | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ios/RNFirebase/admob/RNFirebaseAdMob.m b/ios/RNFirebase/admob/RNFirebaseAdMob.m index 398f38fd..70dc4a29 100644 --- a/ios/RNFirebase/admob/RNFirebaseAdMob.m +++ b/ios/RNFirebase/admob/RNFirebaseAdMob.m @@ -35,7 +35,7 @@ RCT_EXPORT_METHOD(initialize: RCT_EXPORT_METHOD(openDebugMenu: (NSString *) appId) { GADDebugOptionsViewController *debugOptionsViewController = [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:appId]; - UIWindow* window = [UIApplication sharedApplication].keyWindow; + UIWindow *window = [UIApplication sharedApplication].keyWindow; [[window rootViewController] presentViewController:debugOptionsViewController animated:YES completion:nil]; } @@ -68,6 +68,11 @@ RCT_EXPORT_METHOD(rewardedVideoShowAd: [rewardedVideo show]; } +RCT_EXPORT_METHOD(clearInterstitial: + (NSString *) adUnit) { + if (_interstitials[adUnit]) [_interstitials removeObjectForKey:adUnit]; +} + - (RNFirebaseAdMobInterstitial *)getOrCreateInterstitial:(NSString *)adUnit { if (_interstitials[adUnit]) { return _interstitials[adUnit]; @@ -187,8 +192,8 @@ RCT_EXPORT_METHOD(rewardedVideoShowAd: NSString *matchText = [value substringWithRange:[match range]]; if (matchText) { NSArray *values = [matchText componentsSeparatedByString:@"x"]; - CGFloat width = (CGFloat)[values[0] intValue]; - CGFloat height = (CGFloat)[values[1] intValue]; + CGFloat width = (CGFloat) [values[0] intValue]; + CGFloat height = (CGFloat) [values[1] intValue]; return GADAdSizeFromCGSize(CGSizeMake(width, height)); } } diff --git a/lib/modules/admob/Interstitial.js b/lib/modules/admob/Interstitial.js index f072b96b..33eb5568 100644 --- a/lib/modules/admob/Interstitial.js +++ b/lib/modules/admob/Interstitial.js @@ -1,4 +1,4 @@ -import { NativeModules } from 'react-native'; +import { NativeModules, Platform } from 'react-native'; import { statics } from './'; import AdRequest from './AdRequest'; import { nativeToJSError } from '../../utils'; @@ -8,6 +8,11 @@ const FirebaseAdMob = NativeModules.RNFirebaseAdMob; export default class Interstitial { constructor(admob: Object, adUnit: string) { + // Interstitials on iOS require a new instance each time + if (Platform.OS === 'ios') { + FirebaseAdMob.clearInterstitial(adUnit); + } + this.admob = admob; this.adUnit = adUnit; this.loaded = false;