2017-06-05 16:00:59 +00:00
|
|
|
#import "RNFirebaseAdMobInterstitial.h"
|
|
|
|
|
|
|
|
@implementation RNFirebaseAdMobInterstitial
|
|
|
|
|
2017-06-20 12:22:09 +00:00
|
|
|
#if __has_include(<GoogleMobileAds/GADMobileAds.h>)
|
|
|
|
|
2017-06-05 16:00:59 +00:00
|
|
|
- (id)initWithProps:(NSString *)adUnit delegate:(RNFirebaseAdMob *)delegate {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
_adUnitID = adUnit;
|
|
|
|
_delegate = delegate;
|
|
|
|
_interstitial = [self createInterstitial];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GADInterstitial *)createInterstitial {
|
|
|
|
GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:_adUnitID];
|
2017-06-07 11:37:32 +00:00
|
|
|
interstitial.delegate = self;
|
2017-06-05 16:00:59 +00:00
|
|
|
return interstitial;
|
|
|
|
}
|
|
|
|
|
2017-06-07 11:37:32 +00:00
|
|
|
- (void)loadAd:(NSDictionary *)request {
|
2017-06-16 14:22:35 +00:00
|
|
|
[_interstitial loadRequest:[RNFirebaseAdMob buildRequest:request]];
|
2017-06-05 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 13:19:06 +00:00
|
|
|
- (void)show {
|
2017-06-07 11:37:32 +00:00
|
|
|
if (_interstitial.isReady) {
|
|
|
|
[_interstitial presentFromRootViewController:[UIApplication sharedApplication].delegate.window.rootViewController];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendJSEvent:(NSString *)type payload:(NSDictionary *)payload {
|
|
|
|
[_delegate sendEventWithName:ADMOB_INTERSTITIAL_EVENT body:@{
|
|
|
|
@"type": type,
|
|
|
|
@"adUnit": _adUnitID,
|
|
|
|
@"payload": payload
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interstitialDidReceiveAd:(nonnull GADInterstitial *)ad {
|
|
|
|
[self sendJSEvent:@"onAdLoaded" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error {
|
2017-06-16 14:22:35 +00:00
|
|
|
[self sendJSEvent:@"onAdFailedToLoad" payload:[RNFirebaseAdMob errorCodeToDictionary:error]];
|
2017-06-07 11:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
|
|
|
|
[self sendJSEvent:@"onAdOpened" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
|
|
|
|
[self sendJSEvent:@"onAdClosed" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
|
|
|
|
[self sendJSEvent:@"onAdLeftApplication" payload:@{}];
|
2017-06-05 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:22:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-06-05 16:00:59 +00:00
|
|
|
@end
|