@capgo/capacitor-admob 7.1.1 → 7.4.5

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.
@@ -0,0 +1,102 @@
1
+ import Foundation
2
+ import UIKit
3
+ import GoogleMobileAds
4
+ import Capacitor
5
+
6
+ class RewardedInterstitialAd: NSObject, Ad {
7
+ let id: Int
8
+ let adUnitId: String
9
+ private var rewardedInterstitialAd: GADRewardedInterstitialAd?
10
+ private weak var plugin: AdmobPlusPlugin?
11
+
12
+ var isLoaded: Bool {
13
+ return rewardedInterstitialAd != nil
14
+ }
15
+
16
+ init(id: Int, adUnitId: String, plugin: AdmobPlusPlugin) {
17
+ self.id = id
18
+ self.adUnitId = adUnitId
19
+ self.plugin = plugin
20
+ super.init()
21
+ }
22
+
23
+ func load(completion: @escaping (Error?) -> Void) {
24
+ let request = AdMobHelper.buildAdRequest()
25
+
26
+ GADRewardedInterstitialAd.load(withAdUnitID: adUnitId, request: request) { [weak self] ad, error in
27
+ guard let self = self else { return }
28
+
29
+ if let error = error {
30
+ self.plugin?.notifyListeners(Events.rewardedInterstitialLoadFail, data: [
31
+ "id": self.id,
32
+ "error": error.localizedDescription
33
+ ])
34
+ completion(error)
35
+ return
36
+ }
37
+
38
+ self.rewardedInterstitialAd = ad
39
+ self.rewardedInterstitialAd?.fullScreenContentDelegate = self
40
+
41
+ self.plugin?.notifyListeners(Events.rewardedInterstitialLoad, data: ["id": self.id])
42
+ completion(nil)
43
+ }
44
+ }
45
+
46
+ func show(completion: @escaping (Error?) -> Void) {
47
+ DispatchQueue.main.async { [weak self] in
48
+ guard let self = self, let rewardedInterstitialAd = self.rewardedInterstitialAd else {
49
+ completion(AdMobError.adNotLoaded)
50
+ return
51
+ }
52
+
53
+ guard let viewController = self.plugin?.bridge?.viewController else {
54
+ completion(AdMobError.unknown("Unable to access view controller"))
55
+ return
56
+ }
57
+
58
+ rewardedInterstitialAd.present(fromRootViewController: viewController) { [weak self] in
59
+ guard let self = self else { return }
60
+ let reward = rewardedInterstitialAd.adReward
61
+ self.plugin?.notifyListeners(Events.rewardedInterstitialReward, data: [
62
+ "id": self.id,
63
+ "reward": [
64
+ "amount": reward.amount.intValue,
65
+ "type": reward.type
66
+ ]
67
+ ])
68
+ }
69
+ completion(nil)
70
+ }
71
+ }
72
+
73
+ func destroy() {
74
+ rewardedInterstitialAd = nil
75
+ }
76
+ }
77
+
78
+ extension RewardedInterstitialAd: GADFullScreenContentDelegate {
79
+ func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
80
+ plugin?.notifyListeners(Events.rewardedInterstitialImpression, data: ["id": id])
81
+ }
82
+
83
+ func adDidRecordClick(_ ad: GADFullScreenPresentingAd) {
84
+ plugin?.notifyListeners(Events.adClick, data: ["id": id])
85
+ }
86
+
87
+ func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
88
+ plugin?.notifyListeners(Events.rewardedInterstitialShowFail, data: [
89
+ "id": id,
90
+ "error": error.localizedDescription
91
+ ])
92
+ }
93
+
94
+ func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
95
+ plugin?.notifyListeners(Events.rewardedInterstitialShow, data: ["id": id])
96
+ }
97
+
98
+ func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
99
+ plugin?.notifyListeners(Events.rewardedInterstitialDismiss, data: ["id": id])
100
+ rewardedInterstitialAd = nil
101
+ }
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-admob",
3
- "version": "7.1.1",
3
+ "version": "7.4.5",
4
4
  "description": "Capacitor plugin to bridge AdMob SDKs for iOS and Android",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,8 +0,0 @@
1
- import Foundation
2
-
3
- @objc public class AdmobPlus: NSObject {
4
- @objc public func echo(_ value: String) -> String {
5
- print(value)
6
- return value
7
- }
8
- }