@capacitor-community/admob 6.1.0 → 6.2.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.
- package/CapacitorCommunityAdmob.podspec +1 -1
- package/package.json +9 -16
- package/ios/Plugin/Banner/BannerAdPluginEvents.swift +0 -8
- package/ios/Plugin/Banner/BannerAdSizeEnum.swift +0 -10
- package/ios/Plugin/Banner/BannerExecutor.swift +0 -186
- package/ios/Plugin/Consent/ConsentExecutor.swift +0 -87
- package/ios/Plugin/Helper/AuthorizationStatusEnum.swift +0 -6
- package/ios/Plugin/Info.plist +0 -24
- package/ios/Plugin/Interstitial/AdInterstitialExecutor.swift +0 -65
- package/ios/Plugin/Interstitial/InterstitialAdPluginEvents.swift +0 -7
- package/ios/Plugin/Models/FullScreenAdEventName.swift +0 -12
- package/ios/Plugin/Plugin.h +0 -10
- package/ios/Plugin/Plugin.m +0 -25
- package/ios/Plugin/Plugin.swift +0 -297
- package/ios/Plugin/Rewarded/AdRewardExecutor.swift +0 -86
- package/ios/Plugin/Rewarded/RewardAdPluginEvents.swift +0 -8
- package/ios/Plugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +0 -86
- package/ios/Plugin/RewardedInterstitial/RewardInterstitialAdPluginEvents.swift +0 -8
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.homepage = package['repository']['url']
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
-
s.source_files = 'ios/
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
14
|
s.ios.deployment_target = '13.0'
|
|
15
15
|
s.swift_version = '5.1'
|
|
16
16
|
s.static_framework = true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/admob",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0-0",
|
|
4
4
|
"description": "A native plugin for AdMob",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
30
|
-
"verify:ios": "
|
|
30
|
+
"verify:ios": "xcodebuild -scheme CapacitorCommunityAdmob -destination generic/platform=iOS",
|
|
31
31
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
32
32
|
"verify:web": "npm run build",
|
|
33
33
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"clean": "rimraf ./dist",
|
|
41
41
|
"watch": "tsc --watch",
|
|
42
42
|
"prepublishOnly": "npm run build",
|
|
43
|
-
"release": "np --no-tests"
|
|
43
|
+
"release": "np --no-tests",
|
|
44
|
+
"prepare": "husky"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@capacitor/android": "^6.0.0",
|
|
@@ -50,27 +51,22 @@
|
|
|
50
51
|
"@capacitor/ios": "^6.0.0",
|
|
51
52
|
"@ionic/eslint-config": "^0.3.0",
|
|
52
53
|
"@ionic/prettier-config": "^1.0.1",
|
|
53
|
-
"@ionic/swiftlint-config": "^
|
|
54
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
54
55
|
"eslint": "^7.11.0",
|
|
55
|
-
"husky": "^
|
|
56
|
-
"lint-staged": "^
|
|
56
|
+
"husky": "^9.1.7",
|
|
57
|
+
"lint-staged": "^15.2.10",
|
|
57
58
|
"np": "^8.0.4",
|
|
58
59
|
"pre-commit": "^1.2.2",
|
|
59
60
|
"prettier": "~2.3.0",
|
|
60
61
|
"prettier-plugin-java": "~1.0.2",
|
|
61
62
|
"rimraf": "^3.0.2",
|
|
62
63
|
"rollup": "^2.32.0",
|
|
63
|
-
"swiftlint": "^
|
|
64
|
+
"swiftlint": "^2.0.0",
|
|
64
65
|
"typescript": "~4.1.5"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
68
|
"@capacitor/core": "^6.0.0"
|
|
68
69
|
},
|
|
69
|
-
"husky": {
|
|
70
|
-
"hooks": {
|
|
71
|
-
"pre-commit": "lint-staged"
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
70
|
"lint-staged": {
|
|
75
71
|
"*.{ts}": [
|
|
76
72
|
"npm run prettier -- --write",
|
|
@@ -79,13 +75,10 @@
|
|
|
79
75
|
"*.{java}": [
|
|
80
76
|
"npm run prettier -- --write",
|
|
81
77
|
"git add"
|
|
82
|
-
],
|
|
83
|
-
"*.swift": [
|
|
84
|
-
"npm run swiftlint -- --fix --format",
|
|
85
|
-
"git add"
|
|
86
78
|
]
|
|
87
79
|
},
|
|
88
80
|
"prettier": "@ionic/prettier-config",
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
89
82
|
"eslintConfig": {
|
|
90
83
|
"extends": "@ionic/eslint-config/recommended"
|
|
91
84
|
},
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
public enum BannerAdPluginEvents: String {
|
|
2
|
-
case SizeChanged = "bannerAdSizeChanged"
|
|
3
|
-
case Closed = "bannerAdClosed"
|
|
4
|
-
case FailedToLoad = "bannerAdFailedToLoad"
|
|
5
|
-
case Opened = "bannerAdOpened"
|
|
6
|
-
case Loaded = "bannerAdLoaded"
|
|
7
|
-
case AdImpression = "bannerAdImpression"
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
public enum BannerAdSizeEnum: String {
|
|
2
|
-
case BANNER = "BANNER"
|
|
3
|
-
case FULL_BANNER = "FULL_BANNER"
|
|
4
|
-
case LARGE_BANNER = "LARGE_BANNER"
|
|
5
|
-
case LEADERBOARD = "LEADERBOARD"
|
|
6
|
-
case MEDIUM_RECTANGLE = "MEDIUM_RECTANGLE"
|
|
7
|
-
case WIDE_SKYSCRAPER = "WIDE_SKYSCRAPER"
|
|
8
|
-
case ADAPTIVE_BANNER = "ADAPTIVE_BANNER"
|
|
9
|
-
// case FLUID = "FLUID"
|
|
10
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
|
|
5
|
-
class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
6
|
-
weak var plugin: AdMob?
|
|
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
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
import UserMessagingPlatform
|
|
5
|
-
|
|
6
|
-
class ConsentExecutor: NSObject {
|
|
7
|
-
weak var plugin: AdMob?
|
|
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
|
-
}
|
package/ios/Plugin/Info.plist
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
-
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
-
<key>CFBundleExecutable</key>
|
|
8
|
-
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
-
<key>CFBundleIdentifier</key>
|
|
10
|
-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
-
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
-
<string>6.0</string>
|
|
13
|
-
<key>CFBundleName</key>
|
|
14
|
-
<string>$(PRODUCT_NAME)</string>
|
|
15
|
-
<key>CFBundlePackageType</key>
|
|
16
|
-
<string>FMWK</string>
|
|
17
|
-
<key>CFBundleShortVersionString</key>
|
|
18
|
-
<string>1.0</string>
|
|
19
|
-
<key>CFBundleVersion</key>
|
|
20
|
-
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
-
<key>NSPrincipalClass</key>
|
|
22
|
-
<string></string>
|
|
23
|
-
</dict>
|
|
24
|
-
</plist>
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
|
|
5
|
-
class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
-
weak var plugin: AdMob?
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
package/ios/Plugin/Plugin.h
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Plugin.
|
|
4
|
-
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Plugin.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
-
|
|
9
|
-
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
-
|
package/ios/Plugin/Plugin.m
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <Capacitor/Capacitor.h>
|
|
3
|
-
|
|
4
|
-
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
-
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
-
CAP_PLUGIN(AdMob, "AdMob",
|
|
7
|
-
CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise);
|
|
8
|
-
CAP_PLUGIN_METHOD(trackingAuthorizationStatus, CAPPluginReturnPromise);
|
|
9
|
-
CAP_PLUGIN_METHOD(requestConsentInfo, CAPPluginReturnPromise);
|
|
10
|
-
CAP_PLUGIN_METHOD(requestTrackingAuthorization, CAPPluginReturnPromise);
|
|
11
|
-
CAP_PLUGIN_METHOD(showConsentForm, CAPPluginReturnPromise);
|
|
12
|
-
CAP_PLUGIN_METHOD(resetConsentInfo, CAPPluginReturnPromise);
|
|
13
|
-
CAP_PLUGIN_METHOD(setApplicationMuted, CAPPluginReturnPromise);
|
|
14
|
-
CAP_PLUGIN_METHOD(setApplicationVolume, CAPPluginReturnPromise);
|
|
15
|
-
CAP_PLUGIN_METHOD(showBanner, CAPPluginReturnPromise);
|
|
16
|
-
CAP_PLUGIN_METHOD(resumeBanner, CAPPluginReturnPromise);
|
|
17
|
-
CAP_PLUGIN_METHOD(hideBanner, CAPPluginReturnPromise);
|
|
18
|
-
CAP_PLUGIN_METHOD(removeBanner, CAPPluginReturnPromise);
|
|
19
|
-
CAP_PLUGIN_METHOD(prepareInterstitial, CAPPluginReturnPromise);
|
|
20
|
-
CAP_PLUGIN_METHOD(showInterstitial, CAPPluginReturnPromise);
|
|
21
|
-
CAP_PLUGIN_METHOD(prepareRewardVideoAd, CAPPluginReturnPromise);
|
|
22
|
-
CAP_PLUGIN_METHOD(showRewardVideoAd, CAPPluginReturnPromise);
|
|
23
|
-
CAP_PLUGIN_METHOD(prepareRewardInterstitialAd, CAPPluginReturnPromise);
|
|
24
|
-
CAP_PLUGIN_METHOD(showRewardInterstitialAd, CAPPluginReturnPromise);
|
|
25
|
-
)
|
package/ios/Plugin/Plugin.swift
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
#if canImport(AppTrackingTransparency)
|
|
5
|
-
import AppTrackingTransparency
|
|
6
|
-
#endif
|
|
7
|
-
|
|
8
|
-
@objc(AdMob)
|
|
9
|
-
public class AdMob: CAPPlugin {
|
|
10
|
-
|
|
11
|
-
var testingDevices: [String] = []
|
|
12
|
-
|
|
13
|
-
private let bannerExecutor = BannerExecutor()
|
|
14
|
-
private let adInterstitialExecutor = AdInterstitialExecutor()
|
|
15
|
-
private let adRewardExecutor = AdRewardExecutor()
|
|
16
|
-
private let adRewardInterstitialExecutor = AdRewardInterstitialExecutor()
|
|
17
|
-
private let consentExecutor = ConsentExecutor()
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Enable SKAdNetwork to track conversions
|
|
21
|
-
* https://developers.google.com/admob/ios/ios14
|
|
22
|
-
*/
|
|
23
|
-
@objc func initialize(_ call: CAPPluginCall) {
|
|
24
|
-
self.bannerExecutor.plugin = self
|
|
25
|
-
self.adInterstitialExecutor.plugin = self
|
|
26
|
-
self.adRewardExecutor.plugin = self
|
|
27
|
-
self.adRewardInterstitialExecutor.plugin = self
|
|
28
|
-
self.adInterstitialExecutor.plugin = self
|
|
29
|
-
self.consentExecutor.plugin = self
|
|
30
|
-
self.setRequestConfiguration(call)
|
|
31
|
-
|
|
32
|
-
GADMobileAds.sharedInstance().start(completionHandler: nil)
|
|
33
|
-
call.resolve([:])
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* DEPRECATED: It's now ship with Admob UMP Consent
|
|
38
|
-
*/
|
|
39
|
-
@objc func requestTrackingAuthorization(_ call: CAPPluginCall) {
|
|
40
|
-
if #available(iOS 14, *) {
|
|
41
|
-
#if canImport(AppTrackingTransparency)
|
|
42
|
-
ATTrackingManager.requestTrackingAuthorization(completionHandler: { _ in
|
|
43
|
-
call.resolve([:])
|
|
44
|
-
})
|
|
45
|
-
#else
|
|
46
|
-
call.resolve([:])
|
|
47
|
-
#endif
|
|
48
|
-
} else {
|
|
49
|
-
call.resolve([:])
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@objc func setApplicationMuted(_ call: CAPPluginCall) {
|
|
54
|
-
if let shouldMute = call.getBool("muted") {
|
|
55
|
-
GADMobileAds.sharedInstance().applicationMuted = shouldMute
|
|
56
|
-
call.resolve([:])
|
|
57
|
-
} else {
|
|
58
|
-
call.reject("muted property cannot be null")
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@objc func setApplicationVolume(_ call: CAPPluginCall) {
|
|
64
|
-
if var volume = call.getFloat("volume") {
|
|
65
|
-
// Clamp volumes.
|
|
66
|
-
if volume < 0.0 {volume = 0.0} else if volume > 1.0 {volume = 1.0}
|
|
67
|
-
|
|
68
|
-
GADMobileAds.sharedInstance().applicationVolume = volume
|
|
69
|
-
|
|
70
|
-
call.resolve([:])
|
|
71
|
-
} else {
|
|
72
|
-
call.reject("volume property cannot be null")
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* AdMob: Banner
|
|
79
|
-
* https://developers.google.com/ad-manager/mobile-ads-sdk/ios/banner?hl=ja
|
|
80
|
-
*/
|
|
81
|
-
@objc func showBanner(_ call: CAPPluginCall) {
|
|
82
|
-
let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/6300978111")
|
|
83
|
-
let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
|
|
84
|
-
|
|
85
|
-
DispatchQueue.main.async {
|
|
86
|
-
self.bannerExecutor.showBanner(call, request, adUnitID)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@objc func hideBanner(_ call: CAPPluginCall) {
|
|
91
|
-
DispatchQueue.main.async {
|
|
92
|
-
self.bannerExecutor.hideBanner(call)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@objc func resumeBanner(_ call: CAPPluginCall) {
|
|
97
|
-
DispatchQueue.main.async {
|
|
98
|
-
self.bannerExecutor.resumeBanner(call)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@objc func removeBanner(_ call: CAPPluginCall) {
|
|
103
|
-
DispatchQueue.main.async {
|
|
104
|
-
self.bannerExecutor.removeBanner(call)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* AdMob: Intertitial
|
|
110
|
-
* https://developers.google.com/admob/ios/interstitial?hl=ja
|
|
111
|
-
*/
|
|
112
|
-
@objc func prepareInterstitial(_ call: CAPPluginCall) {
|
|
113
|
-
let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/1033173712")
|
|
114
|
-
let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
|
|
115
|
-
|
|
116
|
-
DispatchQueue.main.async {
|
|
117
|
-
self.adInterstitialExecutor.prepareInterstitial(call, request, adUnitID)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@objc func showInterstitial(_ call: CAPPluginCall) {
|
|
122
|
-
DispatchQueue.main.async {
|
|
123
|
-
self.adInterstitialExecutor.showInterstitial(call)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* AdMob: Rewarded Ads
|
|
129
|
-
* https://developers.google.com/ad-manager/mobile-ads-sdk/ios/rewarded-ads
|
|
130
|
-
*/
|
|
131
|
-
@objc func prepareRewardVideoAd(_ call: CAPPluginCall) {
|
|
132
|
-
let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/1712485313")
|
|
133
|
-
let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
|
|
134
|
-
|
|
135
|
-
DispatchQueue.main.async {
|
|
136
|
-
self.adRewardExecutor.prepareRewardVideoAd(call, request, adUnitID)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@objc func showRewardVideoAd(_ call: CAPPluginCall) {
|
|
141
|
-
DispatchQueue.main.async {
|
|
142
|
-
self.adRewardExecutor.showRewardVideoAd(call)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* AdMob: Rewarded Interstitial Ads
|
|
148
|
-
* https://developers.google.com/ad-manager/mobile-ads-sdk/ios/rewarded-interstitial
|
|
149
|
-
*/
|
|
150
|
-
@objc func prepareRewardInterstitialAd(_ call: CAPPluginCall) {
|
|
151
|
-
let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/6978759866")
|
|
152
|
-
let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
|
|
153
|
-
|
|
154
|
-
DispatchQueue.main.async {
|
|
155
|
-
self.adRewardInterstitialExecutor.prepareRewardInterstitialAd(call, request, adUnitID)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@objc func showRewardInterstitialAd(_ call: CAPPluginCall) {
|
|
160
|
-
DispatchQueue.main.async {
|
|
161
|
-
self.adRewardInterstitialExecutor.showRewardInterstitialAd(call)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
@objc func trackingAuthorizationStatus(_ call: CAPPluginCall) {
|
|
166
|
-
DispatchQueue.main.async {
|
|
167
|
-
if #available(iOS 14, *) {
|
|
168
|
-
switch ATTrackingManager.trackingAuthorizationStatus {
|
|
169
|
-
case .authorized:
|
|
170
|
-
call.resolve(["status": AuthorizationStatusEnum.Authorized.rawValue])
|
|
171
|
-
break
|
|
172
|
-
case .denied:
|
|
173
|
-
call.resolve(["status": AuthorizationStatusEnum.Denied.rawValue])
|
|
174
|
-
break
|
|
175
|
-
case .restricted:
|
|
176
|
-
call.resolve(["status": AuthorizationStatusEnum.Restricted.rawValue])
|
|
177
|
-
break
|
|
178
|
-
case .notDetermined:
|
|
179
|
-
call.resolve(["status": AuthorizationStatusEnum.NotDetermined.rawValue])
|
|
180
|
-
break
|
|
181
|
-
@unknown default:
|
|
182
|
-
call.reject("trackingAuthorizationStatus can't get status")
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
call.resolve(["status": AuthorizationStatusEnum.Authorized])
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Admob: User Message Platform
|
|
192
|
-
* https://support.google.com/admob/answer/10113005?hl=en
|
|
193
|
-
*/
|
|
194
|
-
@objc func requestConsentInfo(_ call: CAPPluginCall) {
|
|
195
|
-
let debugGeography = call.getInt("debugGeography", 0)
|
|
196
|
-
|
|
197
|
-
let testDeviceJSArray = call.getArray("testDeviceIdentifiers") ?? []
|
|
198
|
-
var testDeviceIdentifiers: [String] = []
|
|
199
|
-
if testDeviceJSArray.count > 0 {
|
|
200
|
-
for deviceId in testDeviceJSArray {
|
|
201
|
-
if let name = deviceId as? String {
|
|
202
|
-
testDeviceIdentifiers.append(name)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let tagForUnderAgeOfConsent = call.getBool("tagForUnderAgeOfConsent", false)
|
|
208
|
-
|
|
209
|
-
DispatchQueue.main.async {
|
|
210
|
-
self.consentExecutor.requestConsentInfo(call, debugGeography, testDeviceIdentifiers, tagForUnderAgeOfConsent)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
@objc func showConsentForm(_ call: CAPPluginCall) {
|
|
215
|
-
DispatchQueue.main.async {
|
|
216
|
-
self.consentExecutor.showConsentForm(call)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
@objc func resetConsentInfo(_ call: CAPPluginCall) {
|
|
221
|
-
DispatchQueue.main.async {
|
|
222
|
-
self.consentExecutor.resetConsentInfo(call)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private func getAdId(_ call: CAPPluginCall, _ testingID: String) -> String {
|
|
227
|
-
let adUnitID = call.getString("adId") ?? testingID
|
|
228
|
-
let isTest = call.getBool("isTesting") ?? false
|
|
229
|
-
if isTest {
|
|
230
|
-
return testingID
|
|
231
|
-
}
|
|
232
|
-
return adUnitID
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private func GADRequestWithOption(_ npa: Bool) -> GADRequest {
|
|
236
|
-
let request = GADRequest()
|
|
237
|
-
|
|
238
|
-
if npa {
|
|
239
|
-
let extras = GADExtras()
|
|
240
|
-
extras.additionalParameters = ["npa": "1"]
|
|
241
|
-
request.register(extras)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return request
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* https://developers.google.com/admob/ios/targeting?hl=ja
|
|
249
|
-
*/
|
|
250
|
-
private func setRequestConfiguration(_ call: CAPPluginCall) {
|
|
251
|
-
|
|
252
|
-
if call.getBool("initializeForTesting") ?? false {
|
|
253
|
-
GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = call.getArray("testingDevices", String.self) ?? []
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if call.getBool("tagForChildDirectedTreatment") == true {
|
|
257
|
-
GADMobileAds.sharedInstance().requestConfiguration.tagForChildDirectedTreatment = true
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if call.getBool("tagForUnderAgeOfConsent") == true {
|
|
261
|
-
GADMobileAds.sharedInstance().requestConfiguration.tagForUnderAgeOfConsent = true
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if call.getString("maxAdContentRating") != nil {
|
|
265
|
-
switch call.getString("maxAdContentRating") {
|
|
266
|
-
case "General":
|
|
267
|
-
GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
|
|
268
|
-
GADMaxAdContentRating.general
|
|
269
|
-
case "ParentalGuidance":
|
|
270
|
-
GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
|
|
271
|
-
GADMaxAdContentRating.parentalGuidance
|
|
272
|
-
case "Teen":
|
|
273
|
-
GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
|
|
274
|
-
GADMaxAdContentRating.teen
|
|
275
|
-
case "MatureAudience":
|
|
276
|
-
GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
|
|
277
|
-
GADMaxAdContentRating.matureAudience
|
|
278
|
-
default:
|
|
279
|
-
print("maxAdContentRating can't find value")
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
func getRootVC() -> UIViewController? {
|
|
286
|
-
var window: UIWindow? = UIApplication.shared.delegate?.window ?? nil
|
|
287
|
-
|
|
288
|
-
if window == nil {
|
|
289
|
-
let scene: UIWindowScene? = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
290
|
-
window = scene?.windows.filter({$0.isKeyWindow}).first
|
|
291
|
-
if window == nil {
|
|
292
|
-
window = scene?.windows.first
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return window?.rootViewController
|
|
296
|
-
}
|
|
297
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
|
|
5
|
-
class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
-
weak var plugin: AdMob?
|
|
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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import GoogleMobileAds
|
|
4
|
-
|
|
5
|
-
class AdRewardInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
-
public weak var plugin: AdMob?
|
|
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
|
-
public 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
|
-
public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
78
|
-
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
79
|
-
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
83
|
-
NSLog("RewardFullScreenDelegate Ad did dismiss full screen content.")
|
|
84
|
-
self.plugin?.notifyListeners(RewardInterstitialAdPluginEvents.Dismissed.rawValue, data: [:])
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|