react-native-google-mobile-ads 6.2.4 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/RNGoogleMobileAds.podspec +1 -1
  2. package/android/build.gradle +23 -3
  3. package/android/src/main/AndroidManifest.xml +6 -0
  4. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAdHelper.kt +106 -0
  5. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.kt +74 -0
  6. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +5 -0
  7. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsFullScreenAdModule.kt +245 -0
  8. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.kt +74 -0
  9. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +2 -1
  10. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.kt +74 -0
  11. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.kt +74 -0
  12. package/docs/displaying-ads.mdx +2 -2
  13. package/docs/european-user-consent.mdx +3 -2
  14. package/docs/index.mdx +5 -1
  15. package/docs/migrating-to-v6.mdx +2 -2
  16. package/ios/RNGoogleMobileAds/RNGoogleMobileAds-Bridging-Header.h +5 -0
  17. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +13 -68
  18. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift +82 -0
  19. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +4 -0
  20. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift +208 -0
  21. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.swift +72 -0
  22. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +13 -107
  23. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.swift +119 -0
  24. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +2 -1
  25. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +13 -144
  26. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.swift +81 -0
  27. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +13 -143
  28. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift +81 -0
  29. package/ios_config.sh +10 -0
  30. package/lib/commonjs/ads/MobileAd.js +1 -1
  31. package/lib/commonjs/ads/MobileAd.js.map +1 -1
  32. package/lib/commonjs/validateAdRequestOptions.js +8 -0
  33. package/lib/commonjs/validateAdRequestOptions.js.map +1 -1
  34. package/lib/commonjs/version.js +1 -1
  35. package/lib/commonjs/version.js.map +1 -1
  36. package/lib/module/ads/MobileAd.js +1 -1
  37. package/lib/module/ads/MobileAd.js.map +1 -1
  38. package/lib/module/validateAdRequestOptions.js +8 -0
  39. package/lib/module/validateAdRequestOptions.js.map +1 -1
  40. package/lib/module/version.js +1 -1
  41. package/lib/module/version.js.map +1 -1
  42. package/lib/typescript/index.d.ts +1 -1
  43. package/lib/typescript/types/RequestOptions.d.ts +6 -0
  44. package/lib/typescript/version.d.ts +1 -1
  45. package/package.json +4 -4
  46. package/src/ads/MobileAd.ts +2 -1
  47. package/src/types/RequestOptions.ts +7 -0
  48. package/src/validateAdRequestOptions.ts +7 -0
  49. package/src/version.ts +1 -1
  50. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +0 -159
  51. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +0 -178
  52. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +0 -199
  53. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +0 -176
  54. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +0 -29
  55. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +0 -33
  56. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +0 -72
  57. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +0 -25
  58. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +0 -25
  59. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +0 -25
@@ -1,4 +1,3 @@
1
- //
2
1
  /**
3
2
  * Copyright (c) 2016-present Invertase Limited & Contributors
4
3
  *
@@ -16,121 +15,28 @@
16
15
  *
17
16
  */
18
17
 
19
- #import <React/RCTUtils.h>
18
+ #import <React/RCTBridgeModule.h>
20
19
 
21
- #import "RNGoogleMobileAdsCommon.h"
22
- #import "RNGoogleMobileAdsFullScreenContentDelegate.h"
23
- #import "RNGoogleMobileAdsInterstitialModule.h"
24
- #import "common/RNSharedUtils.h"
25
-
26
- static __strong NSMutableDictionary *interstitialMap;
27
- static __strong NSMutableDictionary *interstitialDelegateMap;
28
-
29
- @implementation RNGoogleMobileAdsInterstitialModule
30
- #pragma mark -
31
- #pragma mark Module Setup
32
-
33
- RCT_EXPORT_MODULE();
20
+ @interface RCT_EXTERN_MODULE (RNGoogleMobileAdsInterstitialModule, NSObject)
34
21
 
35
22
  - (dispatch_queue_t)methodQueue {
36
23
  return dispatch_get_main_queue();
37
24
  }
38
25
 
39
- - (id)init {
40
- self = [super init];
41
- static dispatch_once_t onceToken;
42
- dispatch_once(&onceToken, ^{
43
- interstitialMap = [[NSMutableDictionary alloc] init];
44
- interstitialDelegateMap = [[NSMutableDictionary alloc] init];
45
- });
46
- return self;
47
- }
48
-
49
26
  + (BOOL)requiresMainQueueSetup {
50
27
  return YES;
51
28
  }
52
29
 
53
- - (void)dealloc {
54
- [self invalidate];
55
- }
56
-
57
- - (void)invalidate {
58
- for (NSNumber *id in [interstitialMap allKeys]) {
59
- [interstitialMap removeObjectForKey:id];
60
- [interstitialDelegateMap removeObjectForKey:id];
61
- }
62
- }
63
-
64
- #pragma mark -
65
- #pragma mark Google Mobile Ads Methods
66
-
67
- RCT_EXPORT_METHOD(interstitialLoad
68
- : (nonnull NSNumber *)requestId
69
- : (NSString *)adUnitId
70
- : (NSDictionary *)adRequestOptions) {
71
- GAMRequest *request = [RNGoogleMobileAdsCommon buildAdRequest:adRequestOptions];
72
-
73
- void (^completionhandler)(GADInterstitialAd *, NSError *) = ^(GADInterstitialAd *ad,
74
- NSError *error) {
75
- if (error) {
76
- NSDictionary *codeAndMessage = [RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
77
- [RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
78
- requestId:requestId
79
- type:GOOGLE_MOBILE_ADS_EVENT_ERROR
80
- adUnitId:adUnitId
81
- error:codeAndMessage
82
- data:nil];
83
- return;
84
- }
85
- GADInterstitialAd *interstitial = ad;
86
- RNGoogleMobileAdsFullScreenContentDelegate *fullScreenContentDelegate =
87
- [[RNGoogleMobileAdsFullScreenContentDelegate alloc] init];
88
- fullScreenContentDelegate.sendAdEvent = GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL;
89
- fullScreenContentDelegate.requestId = requestId;
90
- fullScreenContentDelegate.adUnitId = ad.adUnitID;
91
- interstitial.fullScreenContentDelegate = fullScreenContentDelegate;
92
- if ([interstitial class] == [GAMInterstitialAd class]) {
93
- ((GAMInterstitialAd *)interstitial).appEventDelegate = fullScreenContentDelegate;
94
- }
95
- interstitialMap[requestId] = interstitial;
96
- interstitialDelegateMap[requestId] = fullScreenContentDelegate;
97
- [RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
98
- requestId:requestId
99
- type:GOOGLE_MOBILE_ADS_EVENT_LOADED
100
- adUnitId:ad.adUnitID
101
- error:nil
102
- data:nil];
103
- };
104
-
105
- if ([RNGoogleMobileAdsCommon isAdManagerUnit:adUnitId]) {
106
- [GAMInterstitialAd loadWithAdManagerAdUnitID:adUnitId
107
- request:request
108
- completionHandler:completionhandler];
109
- } else {
110
- [GADInterstitialAd loadWithAdUnitID:adUnitId
111
- request:request
112
- completionHandler:completionhandler];
113
- }
114
- }
115
-
116
- RCT_EXPORT_METHOD(interstitialShow
117
- : (nonnull NSNumber *)requestId
118
- : (NSString *)adUnitId
119
- : (NSDictionary *)showOptions
120
- : (RCTPromiseResolveBlock)resolve
121
- : (RCTPromiseRejectBlock)reject) {
122
- GADInterstitialAd *interstitial = interstitialMap[requestId];
123
- if (interstitial) {
124
- [interstitial presentFromRootViewController:RNGoogleMobileAdsCommon.currentViewController];
125
- resolve([NSNull null]);
126
- } else {
127
- [RNSharedUtils
128
- rejectPromiseWithUserInfo:reject
129
- userInfo:[@{
130
- @"code" : @"not-ready",
131
- @"message" : @"Interstitial ad attempted to show but was not ready.",
132
- } mutableCopy]];
133
- }
134
- }
30
+ RCT_EXTERN_METHOD(interstitialLoad
31
+ : (nonnull NSNumber *)requestId forAdUnitId
32
+ : (nonnull NSString *)adUnitId withAdRequestOptions
33
+ : (nonnull NSDictionary *)adRequestOptions)
34
+
35
+ RCT_EXTERN_METHOD(interstitialShow
36
+ : (nonnull NSNumber *)requestId forAdUnitId
37
+ : (nonnull NSString *)adUnitId withShowOptions
38
+ : (NSDictionary *)showOptions withResolve
39
+ : (RCTPromiseResolveBlock)resolve withReject
40
+ : (RCTPromiseRejectBlock)reject)
135
41
 
136
42
  @end
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import Foundation
19
+ import GoogleMobileAds
20
+
21
+ @objc(RNGoogleMobileAdsInterstitialModule)
22
+ class RNGoogleMobileAdsInterstitialModule: NSObject {
23
+ let ad = RNGoogleMobileAdsInterstitialAd()
24
+ let gamAd = RNGoogleMobileAdsGAMInterstitialAd()
25
+
26
+ deinit {
27
+ invalidate()
28
+ }
29
+
30
+ @objc
31
+ func invalidate() {
32
+ ad.invalidate()
33
+ gamAd.invalidate()
34
+ }
35
+
36
+ @objc(interstitialLoad:forAdUnitId:withAdRequestOptions:)
37
+ func interstitialLoad(
38
+ requestId: NSNumber,
39
+ adUnitId: String,
40
+ adRequestOptions: Dictionary<String, Any>
41
+ ) {
42
+ if (RNGoogleMobileAdsCommon.isAdManagerUnit(adUnitId)) {
43
+ gamAd.load(
44
+ requestId: requestId.intValue,
45
+ adUnitId: adUnitId,
46
+ adRequestOptions: adRequestOptions
47
+ )
48
+ } else {
49
+ ad.load(
50
+ requestId: requestId.intValue,
51
+ adUnitId: adUnitId,
52
+ adRequestOptions: adRequestOptions
53
+ )
54
+ }
55
+ }
56
+
57
+ @objc(interstitialShow:forAdUnitId:withShowOptions:withResolve:withReject:)
58
+ func interstitialShow(
59
+ requestId: NSNumber,
60
+ adUnitId: String,
61
+ showOptions: Dictionary<String, Any>,
62
+ resolve: RCTPromiseResolveBlock?,
63
+ reject: RCTPromiseRejectBlock?
64
+ ) {
65
+ if (RNGoogleMobileAdsCommon.isAdManagerUnit(adUnitId)) {
66
+ gamAd.show(
67
+ requestId: requestId.intValue,
68
+ adUnitId: adUnitId,
69
+ showOptions: showOptions,
70
+ resolve: resolve,
71
+ reject: reject
72
+ )
73
+ } else {
74
+ ad.show(
75
+ requestId: requestId.intValue,
76
+ adUnitId: adUnitId,
77
+ showOptions: showOptions,
78
+ resolve: resolve,
79
+ reject: reject
80
+ )
81
+ }
82
+ }
83
+
84
+ class RNGoogleMobileAdsInterstitialAd: RNGoogleMobileAdsFullScreenAd<GADInterstitialAd> {
85
+ override func getAdEventName() -> String {
86
+ return GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
87
+ }
88
+
89
+ override func loadAd(
90
+ adUnitId: String,
91
+ adRequest: GAMRequest,
92
+ completionHandler: @escaping (GADInterstitialAd?, Error?) -> ()
93
+ ) {
94
+ GADInterstitialAd.load(
95
+ withAdUnitID: adUnitId,
96
+ request: adRequest,
97
+ completionHandler: completionHandler
98
+ )
99
+ }
100
+ }
101
+
102
+ class RNGoogleMobileAdsGAMInterstitialAd: RNGoogleMobileAdsFullScreenAd<GAMInterstitialAd> {
103
+ override func getAdEventName() -> String {
104
+ return GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
105
+ }
106
+
107
+ override func loadAd(
108
+ adUnitId: String,
109
+ adRequest: GAMRequest,
110
+ completionHandler: @escaping (GAMInterstitialAd?, Error?) -> ()
111
+ ) {
112
+ GAMInterstitialAd.load(
113
+ withAdManagerAdUnitID: adUnitId,
114
+ request: adRequest,
115
+ completionHandler: completionHandler
116
+ )
117
+ }
118
+ }
119
+ }
@@ -115,8 +115,9 @@ RCT_EXPORT_METHOD(openAdInspector
115
115
  stringWithFormat:@"CODE_%d", error.code],
116
116
  @"message" : error.description,
117
117
  } mutableCopy]];
118
+ } else {
119
+ resolve(nil);
118
120
  }
119
- resolve(nil);
120
121
  }];
121
122
  }
122
123
 
@@ -1,4 +1,3 @@
1
- //
2
1
  /**
3
2
  * Copyright (c) 2016-present Invertase Limited & Contributors
4
3
  *
@@ -16,158 +15,28 @@
16
15
  *
17
16
  */
18
17
 
19
- #import <React/RCTUtils.h>
18
+ #import <React/RCTBridgeModule.h>
20
19
 
21
- #import "RNGoogleMobileAdsCommon.h"
22
- #import "RNGoogleMobileAdsFullScreenContentDelegate.h"
23
- #import "RNGoogleMobileAdsRewardedInterstitialModule.h"
24
- #import "common/RNSharedUtils.h"
25
-
26
- static __strong NSMutableDictionary *rewardedInterstitialMap;
27
- static __strong NSMutableDictionary *rewardedInterstitialDelegateMap;
28
-
29
- @implementation RNGoogleMobileAdsRewardedInterstitialModule
30
- #pragma mark -
31
- #pragma mark Module Setup
32
-
33
- RCT_EXPORT_MODULE();
20
+ @interface RCT_EXTERN_MODULE (RNGoogleMobileAdsRewardedInterstitialModule, NSObject)
34
21
 
35
22
  - (dispatch_queue_t)methodQueue {
36
23
  return dispatch_get_main_queue();
37
24
  }
38
25
 
39
- - (id)init {
40
- self = [super init];
41
- static dispatch_once_t onceToken;
42
- dispatch_once(&onceToken, ^{
43
- rewardedInterstitialMap = [[NSMutableDictionary alloc] init];
44
- rewardedInterstitialDelegateMap = [[NSMutableDictionary alloc] init];
45
- });
46
- return self;
47
- }
48
-
49
26
  + (BOOL)requiresMainQueueSetup {
50
27
  return YES;
51
28
  }
52
29
 
53
- - (void)dealloc {
54
- [self invalidate];
55
- }
56
-
57
- - (void)invalidate {
58
- for (NSNumber *id in [rewardedInterstitialMap allKeys]) {
59
- [rewardedInterstitialMap removeObjectForKey:id];
60
- [rewardedInterstitialDelegateMap removeObjectForKey:id];
61
- }
62
- }
63
-
64
- #pragma mark -
65
- #pragma mark Google Mobile Ads Methods
66
-
67
- RCT_EXPORT_METHOD(rewardedInterstitialLoad
68
- : (nonnull NSNumber *)requestId
69
- : (NSString *)adUnitId
70
- : (NSDictionary *)adRequestOptions) {
71
- [GADRewardedInterstitialAd
72
- loadWithAdUnitID:adUnitId
73
- request:[RNGoogleMobileAdsCommon buildAdRequest:adRequestOptions]
74
- completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
75
- if (error) {
76
- NSDictionary *codeAndMessage =
77
- [RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
78
- [RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
79
- requestId:requestId
80
- type:GOOGLE_MOBILE_ADS_EVENT_ERROR
81
- adUnitId:adUnitId
82
- error:codeAndMessage
83
- data:nil];
84
- return;
85
- }
86
- GADRewardedInterstitialAd *rewardedInterstitialAd = ad;
87
-
88
- NSDictionary *serverSideVerificationOptions =
89
- [adRequestOptions objectForKey:@"serverSideVerificationOptions"];
90
-
91
- if (serverSideVerificationOptions != nil) {
92
- GADServerSideVerificationOptions *options =
93
- [[GADServerSideVerificationOptions alloc] init];
94
-
95
- NSString *userId = [serverSideVerificationOptions valueForKey:@"userId"];
96
-
97
- if (userId != nil) {
98
- options.userIdentifier = userId;
99
- }
100
-
101
- NSString *customData = [serverSideVerificationOptions valueForKey:@"customData"];
102
-
103
- if (customData != nil) {
104
- options.customRewardString = customData;
105
- }
106
-
107
- [rewardedInterstitialAd setServerSideVerificationOptions:options];
108
- }
109
-
110
- RNGoogleMobileAdsFullScreenContentDelegate *fullScreenContentDelegate =
111
- [[RNGoogleMobileAdsFullScreenContentDelegate alloc] init];
112
- fullScreenContentDelegate.sendAdEvent = GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL;
113
- fullScreenContentDelegate.requestId = requestId;
114
- fullScreenContentDelegate.adUnitId = ad.adUnitID;
115
- rewardedInterstitialAd.fullScreenContentDelegate = fullScreenContentDelegate;
116
- rewardedInterstitialMap[requestId] = rewardedInterstitialAd;
117
- rewardedInterstitialDelegateMap[requestId] = fullScreenContentDelegate;
118
- GADAdReward *reward = rewardedInterstitialAd.adReward;
119
- NSMutableDictionary *data = [NSMutableDictionary dictionary];
120
- if (reward.type != nil) {
121
- [data setValue:reward.type forKey:@"type"];
122
- }
123
- if (reward.amount != nil) {
124
- [data setValue:reward.amount forKey:@"amount"];
125
- }
126
- [RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
127
- requestId:requestId
128
- type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED
129
- adUnitId:ad.adUnitID
130
- error:nil
131
- data:data];
132
- }];
133
- }
134
-
135
- RCT_EXPORT_METHOD(rewardedInterstitialShow
136
- : (nonnull NSNumber *)requestId
137
- : (NSString *)adUnitId
138
- : (NSDictionary *)showOptions
139
- : (RCTPromiseResolveBlock)resolve
140
- : (RCTPromiseRejectBlock)reject) {
141
- GADRewardedInterstitialAd *rewardedInterstitialAd = rewardedInterstitialMap[requestId];
142
-
143
- if (rewardedInterstitialAd) {
144
- [rewardedInterstitialAd
145
- presentFromRootViewController:RNGoogleMobileAdsCommon.currentViewController
146
- userDidEarnRewardHandler:^{
147
- GADAdReward *reward = rewardedInterstitialAd.adReward;
148
- NSMutableDictionary *data = [NSMutableDictionary dictionary];
149
- if (reward.type != nil) {
150
- [data setValue:reward.type forKey:@"type"];
151
- }
152
- if (reward.amount != nil) {
153
- [data setValue:reward.amount forKey:@"amount"];
154
- }
155
- [RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
156
- requestId:requestId
157
- type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD
158
- adUnitId:rewardedInterstitialAd.adUnitID
159
- error:nil
160
- data:data];
161
- }];
162
- } else {
163
- [RNSharedUtils
164
- rejectPromiseWithUserInfo:reject
165
- userInfo:[@{
166
- @"code" : @"not-ready",
167
- @"message" :
168
- @"Rewarded Interstitial ad attempted to show but was not ready.",
169
- } mutableCopy]];
170
- }
171
- }
30
+ RCT_EXTERN_METHOD(rewardedInterstitialLoad
31
+ : (nonnull NSNumber *)requestId forAdUnitId
32
+ : (nonnull NSString *)adUnitId withAdRequestOptions
33
+ : (nonnull NSDictionary *)adRequestOptions)
34
+
35
+ RCT_EXTERN_METHOD(rewardedInterstitialShow
36
+ : (nonnull NSNumber *)requestId forAdUnitId
37
+ : (nonnull NSString *)adUnitId withShowOptions
38
+ : (NSDictionary *)showOptions withResolve
39
+ : (RCTPromiseResolveBlock)resolve withReject
40
+ : (RCTPromiseRejectBlock)reject)
172
41
 
173
42
  @end
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import Foundation
19
+ import GoogleMobileAds
20
+
21
+ @objc(RNGoogleMobileAdsRewardedInterstitialModule)
22
+ class RNGoogleMobileAdsRewardedInterstitialModule: NSObject {
23
+ let ad = RNGoogleMobileAdsRewardedInterstitialAd()
24
+
25
+ deinit {
26
+ invalidate()
27
+ }
28
+
29
+ @objc
30
+ func invalidate() {
31
+ ad.invalidate()
32
+ }
33
+
34
+ @objc(rewardedInterstitialLoad:forAdUnitId:withAdRequestOptions:)
35
+ func rewardedInterstitialLoad(
36
+ requestId: NSNumber,
37
+ adUnitId: String,
38
+ adRequestOptions: Dictionary<String, Any>
39
+ ) {
40
+ ad.load(
41
+ requestId: requestId.intValue,
42
+ adUnitId: adUnitId,
43
+ adRequestOptions: adRequestOptions
44
+ )
45
+ }
46
+
47
+ @objc(rewardedInterstitialShow:forAdUnitId:withShowOptions:withResolve:withReject:)
48
+ func rewardedInterstitialShow(
49
+ requestId: NSNumber,
50
+ adUnitId: String,
51
+ showOptions: Dictionary<String, Any>,
52
+ resolve: RCTPromiseResolveBlock?,
53
+ reject: RCTPromiseRejectBlock?
54
+ ) {
55
+ ad.show(
56
+ requestId: requestId.intValue,
57
+ adUnitId: adUnitId,
58
+ showOptions: showOptions,
59
+ resolve: resolve,
60
+ reject: reject
61
+ )
62
+ }
63
+
64
+ class RNGoogleMobileAdsRewardedInterstitialAd: RNGoogleMobileAdsFullScreenAd<GADRewardedInterstitialAd> {
65
+ override func getAdEventName() -> String {
66
+ return GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
67
+ }
68
+
69
+ override func loadAd(
70
+ adUnitId: String,
71
+ adRequest: GAMRequest,
72
+ completionHandler: @escaping (GADRewardedInterstitialAd?, Error?) -> ()
73
+ ) {
74
+ GADRewardedInterstitialAd.load(
75
+ withAdUnitID: adUnitId,
76
+ request: adRequest,
77
+ completionHandler: completionHandler
78
+ )
79
+ }
80
+ }
81
+ }