[admob][ios] Fix an issue whereby interstitials on iOS could not be reused with the same adUnit ID

This commit is contained in:
Elliot Hesp 2017-07-04 15:39:56 +01:00
parent 43410bbadd
commit 92b3860230
2 changed files with 14 additions and 4 deletions

View File

@ -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));
}
}

View File

@ -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;