Skip to content

Commit

Permalink
[admob][ios] Fix an issue whereby interstitials on iOS could not be r…
Browse files Browse the repository at this point in the history
…eused with the same adUnit ID
  • Loading branch information
Ehesp committed Jul 4, 2017
1 parent 43410bb commit 92b3860
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions ios/RNFirebase/admob/RNFirebaseAdMob.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (dispatch_queue_t)methodQueue {
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];
}
Expand Down Expand Up @@ -68,6 +68,11 @@ - (dispatch_queue_t)methodQueue {
[rewardedVideo show];
}

RCT_EXPORT_METHOD(clearInterstitial:
(NSString *) adUnit) {
if (_interstitials[adUnit]) [_interstitials removeObjectForKey:adUnit];
}

- (RNFirebaseAdMobInterstitial *)getOrCreateInterstitial:(NSString *)adUnit {
if (_interstitials[adUnit]) {
return _interstitials[adUnit];
Expand Down Expand Up @@ -187,8 +192,8 @@ + (GADAdSize)stringToAdSize:(NSString *)value {
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));
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/admob/Interstitial.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit 92b3860

Please sign in to comment.