[ios][admob] Ensure previous banner is removed from view when re-rendering

This commit is contained in:
Elliot Hesp 2017-06-16 15:35:12 +01:00
parent 0525672860
commit 6af227b648
2 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,8 @@
@interface BannerComponent : UIView <GADBannerViewDelegate>
@property GADBannerView *banner;
@property GADBannerView *banner;
@property (nonatomic, assign) BOOL requested;
@property (nonatomic, copy) NSString *size;
@property (nonatomic, copy) NSString *unitId;

View File

@ -5,6 +5,9 @@
@implementation BannerComponent
- (void)initBanner:(GADAdSize)adSize {
if (_requested) {
[_banner removeFromSuperview];
}
_banner = [[GADBannerView alloc] initWithAdSize:adSize];
_banner.rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
_banner.delegate = self;
@ -27,6 +30,7 @@
- (void)requestAd {
if (_unitId == nil || _size == nil || _request == nil) {
[self setRequested:NO];
return;
}
@ -39,6 +43,7 @@
}];
_banner.adUnitID = _unitId;
[self setRequested:YES];
[_banner loadRequest:[RNFirebaseAdMob buildRequest:_request]];
}