2017-06-07 13:19:06 +00:00
|
|
|
#import "RNFirebaseAdMobRewardedVideo.h"
|
2017-10-26 10:55:07 +00:00
|
|
|
#import "RNFirebaseUtil.h"
|
2017-06-07 13:19:06 +00:00
|
|
|
|
|
|
|
@implementation RNFirebaseAdMobRewardedVideo
|
|
|
|
|
2017-06-20 12:22:09 +00:00
|
|
|
#if __has_include(<GoogleMobileAds/GADMobileAds.h>)
|
|
|
|
|
2017-06-07 13:19:06 +00:00
|
|
|
- (id)initWithProps:(NSString *)adUnit delegate:(RNFirebaseAdMob *)delegate {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
_adUnitID = adUnit;
|
|
|
|
_delegate = delegate;
|
|
|
|
_videoAd = [self createRewardedVideo];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GADRewardBasedVideoAd *)createRewardedVideo {
|
|
|
|
GADRewardBasedVideoAd *videoAd = [GADRewardBasedVideoAd sharedInstance];
|
|
|
|
videoAd.delegate = self;
|
|
|
|
return videoAd;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadAd:(NSDictionary *)request {
|
2017-06-16 14:22:35 +00:00
|
|
|
[_videoAd loadRequest:[RNFirebaseAdMob buildRequest:request] withAdUnitID:_adUnitID];
|
2017-06-07 13:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)show {
|
|
|
|
if (_videoAd.isReady) {
|
|
|
|
[_videoAd presentFromRootViewController:[UIApplication sharedApplication].delegate.window.rootViewController];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendJSEvent:(NSString *)type payload:(NSDictionary *)payload {
|
2017-10-26 10:55:07 +00:00
|
|
|
[RNFirebaseUtil sendJSEvent:self.delegate name:ADMOB_REWARDED_VIDEO_EVENT body:@{
|
2017-06-07 13:19:06 +00:00
|
|
|
@"type": type,
|
|
|
|
@"adUnit": _adUnitID,
|
|
|
|
@"payload": payload
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
|
|
|
|
didRewardUserWithReward:(GADAdReward *)reward {
|
|
|
|
[self sendJSEvent:@"onRewarded" payload:@{
|
|
|
|
@"type":reward.type,
|
|
|
|
@"amount":reward.amount,
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAdDidReceiveAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
|
|
|
|
[self sendJSEvent:@"onAdLoaded" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAdDidOpen:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
|
|
|
|
[self sendJSEvent:@"onAdOpened" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAdDidStartPlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
|
|
|
|
[self sendJSEvent:@"onRewardedVideoStarted" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAdDidClose:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
|
|
|
|
[self sendJSEvent:@"onAdClosed" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAdWillLeaveApplication:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
|
|
|
|
[self sendJSEvent:@"onAdLeftApplication" payload:@{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
|
|
|
|
didFailToLoadWithError:(NSError *)error {
|
2017-06-16 14:22:35 +00:00
|
|
|
[self sendJSEvent:@"onAdFailedToLoad" payload:[RNFirebaseAdMob errorCodeToDictionary:error]];
|
2017-06-07 13:19:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:22:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-10-26 10:55:07 +00:00
|
|
|
@end
|