@capacitor-community/admob 6.2.0-0 → 6.2.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.
- package/Package.swift +30 -0
- package/README.md +6 -0
- package/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java +81 -91
- package/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java +16 -20
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/AdInterstitialExecutor.java +17 -21
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java +19 -23
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/AdRewardInterstitialExecutor.java +23 -27
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -4
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/AdMobPlugin/AdMobPlugin.swift +317 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerAdPluginEvents.swift +8 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerAdSizeEnum.swift +10 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift +186 -0
- package/ios/Sources/AdMobPlugin/Consent/ConsentExecutor.swift +87 -0
- package/ios/Sources/AdMobPlugin/Helper/AuthorizationStatusEnum.swift +6 -0
- package/ios/Sources/AdMobPlugin/Interstitial/AdInterstitialExecutor.swift +65 -0
- package/ios/Sources/AdMobPlugin/Interstitial/InterstitialAdPluginEvents.swift +7 -0
- package/ios/Sources/AdMobPlugin/Models/FullScreenAdEventName.swift +12 -0
- package/ios/Sources/AdMobPlugin/Rewarded/AdRewardExecutor.swift +86 -0
- package/ios/Sources/AdMobPlugin/Rewarded/RewardAdPluginEvents.swift +8 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +86 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/RewardInterstitialAdPluginEvents.swift +8 -0
- package/ios/Tests/AdMobPluginTests/AdMobPluginTests.swift +15 -0
- package/package.json +14 -11
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
|
|
5
|
+
class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
6
|
+
weak var plugin: AdMobPlugin?
|
|
7
|
+
var bannerView: GADBannerView!
|
|
8
|
+
|
|
9
|
+
func showBanner(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
10
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
11
|
+
|
|
12
|
+
let adSize = call.getString("adSize") ?? "ADAPTIVE_BANNER"
|
|
13
|
+
let adPosition = call.getString("position") ?? "BOTTOM_CENTER"
|
|
14
|
+
let adMargin = call.getInt("margin") ?? 0
|
|
15
|
+
|
|
16
|
+
var bannerSize: GADAdSize
|
|
17
|
+
|
|
18
|
+
switch adSize {
|
|
19
|
+
case "BANNER":
|
|
20
|
+
bannerSize = GADAdSizeBanner
|
|
21
|
+
break
|
|
22
|
+
case "LARGE_BANNER":
|
|
23
|
+
bannerSize = GADAdSizeLargeBanner
|
|
24
|
+
break
|
|
25
|
+
case "FULL_BANNER":
|
|
26
|
+
bannerSize = GADAdSizeFullBanner
|
|
27
|
+
break
|
|
28
|
+
case "LEADERBOARD":
|
|
29
|
+
bannerSize = GADAdSizeLeaderboard
|
|
30
|
+
break
|
|
31
|
+
case "MEDIUM_RECTANGLE":
|
|
32
|
+
bannerSize = GADAdSizeMediumRectangle
|
|
33
|
+
break
|
|
34
|
+
case "SMART_BANNER":
|
|
35
|
+
bannerSize = kGADAdSizeSmartBannerPortrait
|
|
36
|
+
break
|
|
37
|
+
default: // ADAPTIVE_BANNER
|
|
38
|
+
let frame = { () -> CGRect in
|
|
39
|
+
// Here safe area is taken into account, hence the view frame is used
|
|
40
|
+
// after the view has been laid out.
|
|
41
|
+
if #available(iOS 11.0, *) {
|
|
42
|
+
return rootViewController.view.frame.inset(by: rootViewController.view.safeAreaInsets)
|
|
43
|
+
} else {
|
|
44
|
+
return rootViewController.view.frame
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
47
|
+
let viewWidth = frame.size.width
|
|
48
|
+
bannerSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
self.bannerView = GADBannerView(adSize: bannerSize)
|
|
53
|
+
self.addBannerViewToView(self.bannerView, adPosition, adMargin)
|
|
54
|
+
self.bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
55
|
+
self.bannerView.adUnitID = adUnitID
|
|
56
|
+
self.bannerView.rootViewController = plugin?.getRootVC()
|
|
57
|
+
|
|
58
|
+
self.bannerView.load(request)
|
|
59
|
+
self.bannerView.delegate = self
|
|
60
|
+
|
|
61
|
+
call.resolve([:])
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func hideBanner(_ call: CAPPluginCall) {
|
|
66
|
+
DispatchQueue.main.async {
|
|
67
|
+
if let rootViewController = self.plugin?.getRootVC() {
|
|
68
|
+
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
69
|
+
NSLog("AdMob: find subView for hideBanner")
|
|
70
|
+
subView.isHidden = true
|
|
71
|
+
} else {
|
|
72
|
+
NSLog("AdMob: not find subView for resumeBanner for hideBanner")
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.SizeChanged.rawValue, data: [
|
|
77
|
+
"width": 0,
|
|
78
|
+
"height": 0
|
|
79
|
+
])
|
|
80
|
+
|
|
81
|
+
call.resolve([:])
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func resumeBanner(_ call: CAPPluginCall) {
|
|
86
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
87
|
+
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
88
|
+
NSLog("AdMob: find subView for resumeBanner")
|
|
89
|
+
subView.isHidden = false
|
|
90
|
+
|
|
91
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.SizeChanged.rawValue, data: [
|
|
92
|
+
"width": subView.frame.width,
|
|
93
|
+
"height": subView.frame.height
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
call.resolve([:])
|
|
97
|
+
|
|
98
|
+
} else {
|
|
99
|
+
NSLog("AdMob: not find subView for resumeBanner")
|
|
100
|
+
call.reject("AdMob: not find subView for resumeBanner")
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func removeBanner(_ call: CAPPluginCall) {
|
|
106
|
+
self.removeBannerViewToView()
|
|
107
|
+
call.resolve([:])
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private func addBannerViewToView(_ bannerView: GADBannerView, _ adPosition: String, _ Margin: Int) {
|
|
111
|
+
removeBannerViewToView()
|
|
112
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
113
|
+
|
|
114
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
115
|
+
bannerView.tag = 2743243288699 // rand
|
|
116
|
+
rootViewController.view.addSubview(bannerView)
|
|
117
|
+
rootViewController.view.addConstraints(
|
|
118
|
+
[NSLayoutConstraint(item: bannerView,
|
|
119
|
+
attribute: adPosition == "TOP_CENTER" ? .top : .bottom,
|
|
120
|
+
relatedBy: .equal,
|
|
121
|
+
toItem: rootViewController.view.safeAreaLayoutGuide,
|
|
122
|
+
attribute: adPosition == "TOP_CENTER" ? .top : .bottom,
|
|
123
|
+
multiplier: 1,
|
|
124
|
+
constant: CGFloat(Int(Margin) * -1)),
|
|
125
|
+
NSLayoutConstraint(item: bannerView,
|
|
126
|
+
attribute: .centerX,
|
|
127
|
+
relatedBy: .equal,
|
|
128
|
+
toItem: rootViewController.view,
|
|
129
|
+
attribute: .centerX,
|
|
130
|
+
multiplier: 1,
|
|
131
|
+
constant: 0)
|
|
132
|
+
])
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private func removeBannerViewToView() {
|
|
137
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
138
|
+
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
139
|
+
bannerView.delegate = nil
|
|
140
|
+
NSLog("AdMob: find subView")
|
|
141
|
+
subView.removeFromSuperview()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// Tells the delegate an ad request loaded an ad.
|
|
147
|
+
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
|
|
148
|
+
NSLog("bannerViewDidReceiveAd")
|
|
149
|
+
|
|
150
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.SizeChanged.rawValue, data: [
|
|
151
|
+
"width": bannerView.frame.width,
|
|
152
|
+
"height": bannerView.frame.height
|
|
153
|
+
])
|
|
154
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.Loaded.rawValue, data: [:])
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// Tells the delegate an ad request failed.
|
|
158
|
+
func bannerView(_ bannerView: GADBannerView,
|
|
159
|
+
didFailToReceiveAdWithError error: Error) {
|
|
160
|
+
NSLog("bannerView:didFailToReceiveAdWithError: \(error.localizedDescription)")
|
|
161
|
+
self.removeBannerViewToView()
|
|
162
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.SizeChanged.rawValue, data: [
|
|
163
|
+
"width": 0,
|
|
164
|
+
"height": 0
|
|
165
|
+
])
|
|
166
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.FailedToLoad.rawValue, data: [
|
|
167
|
+
"code": 0,
|
|
168
|
+
"message": error.localizedDescription
|
|
169
|
+
])
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
|
|
173
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.AdImpression.rawValue, data: [:])
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/// Tells the delegate that a full-screen view will be presented in response
|
|
177
|
+
/// to the user clicking on an ad.
|
|
178
|
+
func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
|
|
179
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.Opened.rawValue, data: [:])
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// Tells the delegate that the full-screen view will be dismissed.
|
|
183
|
+
func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
|
|
184
|
+
self.plugin?.notifyListeners(BannerAdPluginEvents.Closed.rawValue, data: [:])
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
import UserMessagingPlatform
|
|
5
|
+
|
|
6
|
+
class ConsentExecutor: NSObject {
|
|
7
|
+
weak var plugin: AdMobPlugin?
|
|
8
|
+
|
|
9
|
+
func requestConsentInfo(_ call: CAPPluginCall, _ debugGeography: Int, _ testDeviceIdentifiers: [String], _ tagForUnderAgeOfConsent: Bool) {
|
|
10
|
+
let parameters = UMPRequestParameters()
|
|
11
|
+
let debugSettings = UMPDebugSettings()
|
|
12
|
+
|
|
13
|
+
debugSettings.geography = UMPDebugGeography(rawValue: debugGeography) ?? UMPDebugGeography.disabled
|
|
14
|
+
debugSettings.testDeviceIdentifiers = testDeviceIdentifiers
|
|
15
|
+
|
|
16
|
+
parameters.debugSettings = debugSettings
|
|
17
|
+
parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent
|
|
18
|
+
|
|
19
|
+
// Request an update to the consent information.
|
|
20
|
+
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
|
|
21
|
+
with: parameters,
|
|
22
|
+
completionHandler: { error in
|
|
23
|
+
if error != nil {
|
|
24
|
+
call.reject("Request consent info failed")
|
|
25
|
+
} else {
|
|
26
|
+
call.resolve([
|
|
27
|
+
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
|
|
28
|
+
"isConsentFormAvailable": UMPConsentInformation.sharedInstance.formStatus == UMPFormStatus.available
|
|
29
|
+
])
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func showConsentForm(_ call: CAPPluginCall) {
|
|
35
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
36
|
+
let formStatus = UMPConsentInformation.sharedInstance.formStatus
|
|
37
|
+
|
|
38
|
+
if formStatus == UMPFormStatus.available {
|
|
39
|
+
UMPConsentForm.load(completionHandler: {form, loadError in
|
|
40
|
+
if loadError != nil {
|
|
41
|
+
call.reject(loadError?.localizedDescription ?? "Load consent form error")
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
|
|
46
|
+
form?.present(from: rootViewController, completionHandler: { dismissError in
|
|
47
|
+
if dismissError != nil {
|
|
48
|
+
call.reject(dismissError?.localizedDescription ?? "Consent dismiss error")
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
call.resolve([
|
|
53
|
+
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus)
|
|
54
|
+
])
|
|
55
|
+
})
|
|
56
|
+
} else {
|
|
57
|
+
call.resolve([
|
|
58
|
+
"status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus)
|
|
59
|
+
])
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
} else {
|
|
63
|
+
call.reject("Consent Form not available")
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
call.reject("No ViewController")
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func resetConsentInfo(_ call: CAPPluginCall) {
|
|
71
|
+
UMPConsentInformation.sharedInstance.reset()
|
|
72
|
+
call.resolve()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func getConsentStatusString(_ consentStatus: UMPConsentStatus) -> String {
|
|
76
|
+
switch consentStatus {
|
|
77
|
+
case UMPConsentStatus.required:
|
|
78
|
+
return "REQUIRED"
|
|
79
|
+
case UMPConsentStatus.notRequired:
|
|
80
|
+
return "NOT_REQUIRED"
|
|
81
|
+
case UMPConsentStatus.obtained:
|
|
82
|
+
return "OBTAINED"
|
|
83
|
+
default:
|
|
84
|
+
return "UNKNOWN"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
|
|
5
|
+
class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
+
weak var plugin: AdMobPlugin?
|
|
7
|
+
var interstitial: GADInterstitialAd!
|
|
8
|
+
|
|
9
|
+
func prepareInterstitial(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
10
|
+
GADInterstitialAd.load(
|
|
11
|
+
withAdUnitID: adUnitID,
|
|
12
|
+
request: request,
|
|
13
|
+
completionHandler: { (ad, error) in
|
|
14
|
+
if let error = error {
|
|
15
|
+
NSLog("Rewarded ad failed to load with error: \(error.localizedDescription)")
|
|
16
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.FailedToLoad.rawValue, data: [
|
|
17
|
+
"code": 0,
|
|
18
|
+
"message": error.localizedDescription
|
|
19
|
+
])
|
|
20
|
+
call.reject("Loading failed")
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
self.interstitial = ad
|
|
25
|
+
self.interstitial.fullScreenContentDelegate = self
|
|
26
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Loaded.rawValue, data: [
|
|
27
|
+
"adUnitId": adUnitID
|
|
28
|
+
])
|
|
29
|
+
call.resolve([
|
|
30
|
+
"adUnitId": adUnitID
|
|
31
|
+
])
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func showInterstitial(_ call: CAPPluginCall) {
|
|
37
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
38
|
+
if let ad = self.interstitial {
|
|
39
|
+
ad.present(fromRootViewController: rootViewController)
|
|
40
|
+
call.resolve([:])
|
|
41
|
+
} else {
|
|
42
|
+
NSLog("Ad wasn't ready")
|
|
43
|
+
call.reject("Ad wasn't ready")
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
49
|
+
NSLog("InterstitialFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
|
|
50
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.FailedToShow.rawValue, data: [
|
|
51
|
+
"code": 0,
|
|
52
|
+
"message": error.localizedDescription
|
|
53
|
+
])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
57
|
+
NSLog("InterstitialFullScreenDelegate Ad did present full screen content.")
|
|
58
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
62
|
+
NSLog("InterstitialFullScreenDelegate Ad did dismiss full screen content.")
|
|
63
|
+
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Dismissed.rawValue, data: [:])
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
public enum InterstitialAdPluginEvents: String {
|
|
2
|
+
case Loaded = "interstitialAdLoaded"
|
|
3
|
+
case FailedToLoad = "interstitialAdFailedToLoad"
|
|
4
|
+
case Showed = "interstitialAdShowed"
|
|
5
|
+
case FailedToShow = "interstitialAdFailedToShow"
|
|
6
|
+
case Dismissed = "interstitialAdDismissed"
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
public enum FullScreenAdEventName: String {
|
|
2
|
+
case onAdLoaded = "onAdLoaded"
|
|
3
|
+
case onAdFailedToLoad = "onAdFailedToLoad"
|
|
4
|
+
case adDidPresentFullScreenContent = "adDidPresentFullScreenContent"
|
|
5
|
+
case didFailToPresentFullScreenContentWithError = "didFailToPresentFullScreenContentWithError"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Follow iOS Event Name
|
|
9
|
+
* https://developers.google.com/admob/ios/api/reference/Protocols/GADFullScreenContentDelegate#-addidpresentfullscreencontent:
|
|
10
|
+
*/
|
|
11
|
+
case adDidDismissFullScreenContent = "adDidDismissFullScreenContent"
|
|
12
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
|
|
5
|
+
class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
+
weak var plugin: AdMobPlugin?
|
|
7
|
+
var rewardedAd: GADRewardedAd!
|
|
8
|
+
|
|
9
|
+
func prepareRewardVideoAd(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
10
|
+
GADRewardedAd.load(
|
|
11
|
+
withAdUnitID: adUnitID,
|
|
12
|
+
request: request,
|
|
13
|
+
completionHandler: { (ad, error) in
|
|
14
|
+
if let error = error {
|
|
15
|
+
NSLog("Rewarded ad failed to load with error: \(error.localizedDescription)")
|
|
16
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.FailedToLoad.rawValue, data: [
|
|
17
|
+
"code": 0,
|
|
18
|
+
"message": error.localizedDescription
|
|
19
|
+
])
|
|
20
|
+
call.reject("Loading failed")
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
self.rewardedAd = ad
|
|
25
|
+
|
|
26
|
+
if let providedOptions = call.getObject("ssv") {
|
|
27
|
+
let ssvOptions = GADServerSideVerificationOptions()
|
|
28
|
+
|
|
29
|
+
if let customData = providedOptions["customData"] as? String {
|
|
30
|
+
NSLog("Sending Custom Data: \(customData) to SSV callback")
|
|
31
|
+
ssvOptions.customRewardString = customData
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if let userId = providedOptions["userId"] as? String {
|
|
35
|
+
NSLog("Sending UserId: \(userId) to SSV callback")
|
|
36
|
+
ssvOptions.userIdentifier = userId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
self.rewardedAd?.serverSideVerificationOptions = ssvOptions
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
self.rewardedAd?.fullScreenContentDelegate = self
|
|
43
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.Loaded.rawValue, data: [
|
|
44
|
+
"adUnitId": adUnitID
|
|
45
|
+
])
|
|
46
|
+
call.resolve([
|
|
47
|
+
"adUnitId": adUnitID
|
|
48
|
+
])
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func showRewardVideoAd(_ call: CAPPluginCall) {
|
|
54
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
55
|
+
if let ad = self.rewardedAd {
|
|
56
|
+
ad.present(fromRootViewController: rootViewController,
|
|
57
|
+
userDidEarnRewardHandler: {
|
|
58
|
+
let reward = ad.adReward
|
|
59
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.Rewarded.rawValue, data: ["type": reward.type, "amount": reward.amount])
|
|
60
|
+
call.resolve(["type": reward.type, "amount": reward.amount])
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
} else {
|
|
64
|
+
call.reject("Reward Video is Not Ready Yet")
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
70
|
+
NSLog("RewardFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
|
|
71
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.FailedToShow.rawValue, data: [
|
|
72
|
+
"code": 0,
|
|
73
|
+
"message": error.localizedDescription
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
78
|
+
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
79
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.Showed.rawValue, data: [:])
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
83
|
+
NSLog("RewardFullScreenDelegate Ad did dismiss full screen content.")
|
|
84
|
+
self.plugin?.notifyListeners(RewardAdPluginEvents.Dismissed.rawValue, data: [:])
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
public enum RewardAdPluginEvents: String {
|
|
2
|
+
case Loaded = "onRewardedVideoAdLoaded"
|
|
3
|
+
case FailedToLoad = "onRewardedVideoAdFailedToLoad"
|
|
4
|
+
case Showed = "onRewardedVideoAdShowed"
|
|
5
|
+
case FailedToShow = "onRewardedVideoAdFailedToShow"
|
|
6
|
+
case Dismissed = "onRewardedVideoAdDismissed"
|
|
7
|
+
case Rewarded = "onRewardedVideoAdReward"
|
|
8
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
|
|
5
|
+
class AdRewardInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
+
weak var plugin: AdMobPlugin?
|
|
7
|
+
var rewardedInterstitialAd: GADRewardedInterstitialAd!
|
|
8
|
+
|
|
9
|
+
func prepareRewardInterstitialAd(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
10
|
+
GADRewardedInterstitialAd.load(
|
|
11
|
+
withAdUnitID: adUnitID,
|
|
12
|
+
request: request,
|
|
13
|
+
completionHandler: { (ad, error) in
|
|
14
|
+
if let error = error {
|
|
15
|
+
NSLog("Rewarded ad failed to load with error: \(error.localizedDescription)")
|
|
16
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.FailedToLoad.rawValue, data: [
|
|
17
|
+
"code": 0,
|
|
18
|
+
"message": error.localizedDescription
|
|
19
|
+
])
|
|
20
|
+
call.reject("Loading failed")
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
self.rewardedInterstitialAd = ad
|
|
25
|
+
|
|
26
|
+
if let providedOptions = call.getObject("ssv") {
|
|
27
|
+
let ssvOptions = GADServerSideVerificationOptions()
|
|
28
|
+
|
|
29
|
+
if let customData = providedOptions["customData"] as? String {
|
|
30
|
+
NSLog("Sending Custom Data: \(customData) to SSV callback")
|
|
31
|
+
ssvOptions.customRewardString = customData
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if let userId = providedOptions["userId"] as? String {
|
|
35
|
+
NSLog("Sending UserId: \(userId) to SSV callback")
|
|
36
|
+
ssvOptions.userIdentifier = userId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
self.rewardedInterstitialAd?.serverSideVerificationOptions = ssvOptions
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
self.rewardedInterstitialAd?.fullScreenContentDelegate = self
|
|
43
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Loaded.rawValue, data: [
|
|
44
|
+
"adUnitId": adUnitID
|
|
45
|
+
])
|
|
46
|
+
call.resolve([
|
|
47
|
+
"adUnitId": adUnitID
|
|
48
|
+
])
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func showRewardInterstitialAd(_ call: CAPPluginCall) {
|
|
54
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
55
|
+
if let ad = self.rewardedInterstitialAd {
|
|
56
|
+
ad.present(fromRootViewController: rootViewController,
|
|
57
|
+
userDidEarnRewardHandler: {
|
|
58
|
+
let reward = ad.adReward
|
|
59
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Rewarded.rawValue, data: ["type": reward.type, "amount": reward.amount])
|
|
60
|
+
call.resolve(["type": reward.type, "amount": reward.amount])
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
} else {
|
|
64
|
+
call.reject("Reward Video is Not Ready Yet")
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
70
|
+
NSLog("RewardFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
|
|
71
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.FailedToShow.rawValue, data: [
|
|
72
|
+
"code": 0,
|
|
73
|
+
"message": error.localizedDescription
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
78
|
+
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
79
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
83
|
+
NSLog("RewardFullScreenDelegate Ad did dismiss full screen content.")
|
|
84
|
+
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Dismissed.rawValue, data: [:])
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
public enum RewardInterstitialAdPluginEvents: String {
|
|
2
|
+
case Loaded = "onRewardedInterstitialAdLoaded"
|
|
3
|
+
case FailedToLoad = "onRewardedInterstitialAdFailedToLoad"
|
|
4
|
+
case Showed = "onRewardedInterstitialAdShowed"
|
|
5
|
+
case FailedToShow = "onRewardedInterstitialAdFailedToShow"
|
|
6
|
+
case Dismissed = "onRewardedInterstitialAdDismissed"
|
|
7
|
+
case Rewarded = "onRewardedInterstitialAdReward"
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import AdMobPlugin
|
|
3
|
+
|
|
4
|
+
class AdMobTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
// let implementation = AdMob()
|
|
10
|
+
// let value = "Hello, World!"
|
|
11
|
+
// let result = implementation.echo(value)
|
|
12
|
+
//
|
|
13
|
+
// XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/admob",
|
|
3
|
-
"version": "6.2.0
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "A native plugin for AdMob",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"android/src/main/",
|
|
14
14
|
"android/build.gradle",
|
|
15
15
|
"dist/",
|
|
16
|
-
"ios/
|
|
16
|
+
"ios/Sources",
|
|
17
|
+
"ios/Tests",
|
|
18
|
+
"Package.swift",
|
|
17
19
|
"CapacitorCommunityAdmob.podspec"
|
|
18
20
|
],
|
|
19
21
|
"author": "Masahiko Sakakibara <sakakibara@rdlabo.jp>",
|
|
@@ -33,10 +35,10 @@
|
|
|
33
35
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
34
36
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
35
37
|
"eslint": "eslint src/. --ext ts",
|
|
36
|
-
"prettier": "prettier \"{src/*.ts,**/*.java}\"",
|
|
38
|
+
"prettier": "prettier \"{src/*.ts,**/*.java}\" --plugin=prettier-plugin-java",
|
|
37
39
|
"swiftlint": "node-swiftlint",
|
|
38
40
|
"docgen": "docgen --api AdMobPlugin --output-readme README.md --output-json dist/docs.json",
|
|
39
|
-
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.
|
|
41
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
40
42
|
"clean": "rimraf ./dist",
|
|
41
43
|
"watch": "tsc --watch",
|
|
42
44
|
"prepublishOnly": "npm run build",
|
|
@@ -49,18 +51,19 @@
|
|
|
49
51
|
"@capacitor/core": "^6.0.0",
|
|
50
52
|
"@capacitor/docgen": "git+https://github.com/rdlabo/capacitor-docgen.git#feat/support_extends_build",
|
|
51
53
|
"@capacitor/ios": "^6.0.0",
|
|
52
|
-
"@ionic/eslint-config": "^0.
|
|
53
|
-
"@ionic/prettier-config": "^
|
|
54
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
55
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
54
56
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
55
|
-
"eslint": "^
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
58
|
+
"eslint": "^8.57.0",
|
|
56
59
|
"husky": "^9.1.7",
|
|
57
60
|
"lint-staged": "^15.2.10",
|
|
58
61
|
"np": "^8.0.4",
|
|
59
62
|
"pre-commit": "^1.2.2",
|
|
60
|
-
"prettier": "
|
|
61
|
-
"prettier-plugin-java": "
|
|
62
|
-
"rimraf": "^
|
|
63
|
-
"rollup": "^
|
|
63
|
+
"prettier": "^3.3.3",
|
|
64
|
+
"prettier-plugin-java": "^2.6.5",
|
|
65
|
+
"rimraf": "^6.0.1",
|
|
66
|
+
"rollup": "^4.24.0",
|
|
64
67
|
"swiftlint": "^2.0.0",
|
|
65
68
|
"typescript": "~4.1.5"
|
|
66
69
|
},
|