Skip to content

Commit 072fd74

Browse files
fix(cordova/ios): fix remaining SDK 12.x API changes
- Restore GAD prefix for GADMaxAdContentRating (NS_TYPED_ENUM, no Swift rename) and GADGetStringFromVersionNumber (C function, no Swift rename) - Rename withAdUnitID: -> with: and fromRootViewController: -> from: in load/present calls across all ad types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ccb2d5c commit 072fd74

6 files changed

Lines changed: 9 additions & 245 deletions

File tree

‎packages/cordova/src/ios/AMBAppOpenAd.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AMBAppOpenAd: AMBAdBase, FullScreenContentDelegate {
2828
clear()
2929

3030
AppOpenAd.load(
31-
withAdUnitID: self.adUnitId,
31+
with: self.adUnitId,
3232
request: adRequest,
3333
completionHandler: { (ad, error) in
3434
if error != nil {
@@ -45,7 +45,7 @@ class AMBAppOpenAd: AMBAdBase, FullScreenContentDelegate {
4545
}
4646

4747
override func show(_ ctx: AMBContext) {
48-
mAd?.present(fromRootViewController: AMBContext.plugin.viewController)
48+
mAd?.present(from: AMBContext.plugin.viewController)
4949
}
5050

5151
func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
Lines changed: 0 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -1,236 +0,0 @@
1-
import Foundation
2-
import UIKit
3-
import GoogleMobileAds
4-
5-
enum AMBCoreError: Error {
6-
case notImplemented
7-
case unknown
8-
}
9-
10-
protocol AMBHelperAdapter {
11-
}
12-
13-
extension AMBHelperAdapter {
14-
}
15-
16-
class AMBHelper {
17-
static let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow })!
18-
19-
static var topAnchor: NSLayoutYAxisAnchor {
20-
if #available(iOS 11.0, *) {
21-
return window.safeAreaLayoutGuide.topAnchor
22-
} else {
23-
return window.topAnchor
24-
}
25-
}
26-
27-
static var bottomAnchor: NSLayoutYAxisAnchor {
28-
if #available(iOS 11.0, *) {
29-
return window.safeAreaLayoutGuide.bottomAnchor
30-
} else {
31-
return window.bottomAnchor
32-
}
33-
}
34-
35-
static var frame: CGRect {
36-
if #available(iOS 11.0, *) {
37-
return window.frame.inset(by: window.safeAreaInsets)
38-
} else {
39-
return window.frame
40-
}
41-
}
42-
43-
let adapter: AMBHelperAdapter
44-
45-
init(_ adapter: AMBHelperAdapter) {
46-
self.adapter = adapter
47-
}
48-
}
49-
50-
protocol AMBCoreContext {
51-
func has(_ name: String) -> Bool
52-
func optBool(_ name: String) -> Bool?
53-
func optFloat(_ name: String) -> Float?
54-
func optInt(_ name: String) -> Int?
55-
func optString(_ name: String, _ defaultValue: String) -> String
56-
func optStringArray(_ name: String) -> [String]?
57-
58-
func resolve(_ data: [String: Any])
59-
func resolve(_ data: Bool)
60-
61-
func reject(_ msg: String)
62-
}
63-
64-
extension AMBCoreContext {
65-
func optString(_ name: String) -> String? {
66-
if has(name) {
67-
return optString(name, "")
68-
}
69-
return nil
70-
}
71-
72-
func optAppMuted() -> Bool? {
73-
return optBool("appMuted")
74-
}
75-
76-
func optAppVolume() -> Float? {
77-
return optFloat("appVolume")
78-
}
79-
80-
func optId() -> String? {
81-
return optString("id")
82-
}
83-
84-
func optPosition() -> String {
85-
return optString("position", "bottom")
86-
}
87-
88-
func optAdUnitID() -> String? {
89-
return optString("adUnitId")
90-
}
91-
92-
func optAd() -> AMBCoreAd? {
93-
guard let id = optId(),
94-
let ad = AMBCoreAd.ads[id]
95-
else {
96-
return nil
97-
}
98-
return ad
99-
}
100-
101-
func optAdOrError() -> AMBCoreAd? {
102-
if let ad = optAd() {
103-
return ad
104-
} else {
105-
reject("Ad not found: \(optId() ?? "-")")
106-
return nil
107-
}
108-
}
109-
110-
func optMaxAdContentRating() -> MaxAdContentRating? {
111-
switch optString("maxAdContentRating") {
112-
case "G":
113-
return MaxAdContentRating.general
114-
case "MA":
115-
return MaxAdContentRating.matureAudience
116-
case "PG":
117-
return MaxAdContentRating.parentalGuidance
118-
case "T":
119-
return MaxAdContentRating.teen
120-
default:
121-
return nil
122-
}
123-
}
124-
125-
func optChildDirectedTreatmentTag() -> Bool? {
126-
return optBool("tagForChildDirectedTreatment")
127-
}
128-
129-
func optUnderAgeOfConsentTag() -> Bool? {
130-
return optBool("tagForUnderAgeOfConsent")
131-
}
132-
133-
func optTestDeviceIds() -> [String]? {
134-
return optStringArray("testDeviceIds")
135-
}
136-
137-
func optRequest() -> Request {
138-
let request = Request()
139-
if let contentURL = optString("contentUrl") {
140-
request.contentURL = contentURL
141-
}
142-
if let keywords = optStringArray("keywords") {
143-
request.keywords = keywords
144-
}
145-
let extras = Extras()
146-
if let npa = optString("npa") {
147-
extras.additionalParameters = ["npa": npa]
148-
}
149-
request.register(extras)
150-
return request
151-
}
152-
153-
func resolve() {
154-
resolve([:])
155-
}
156-
157-
func resolve(_ data: Bool) {
158-
resolve(["value": data])
159-
}
160-
161-
func reject() {
162-
return reject(AMBCoreError.unknown)
163-
}
164-
165-
func reject(_ error: Error) {
166-
reject(error.localizedDescription)
167-
}
168-
169-
func configure() {
170-
if let muted = optAppMuted() {
171-
MobileAds.shared.applicationMuted = muted
172-
}
173-
if let volume = optAppVolume() {
174-
MobileAds.shared.applicationVolume = volume
175-
}
176-
177-
let requestConfiguration = MobileAds.shared.requestConfiguration
178-
if let maxAdContentRating = optMaxAdContentRating() {
179-
requestConfiguration.maxAdContentRating = maxAdContentRating
180-
}
181-
if let tag = optChildDirectedTreatmentTag() {
182-
requestConfiguration.tagForChildDirectedTreatment = NSNumber(value: tag)
183-
}
184-
if let tag = optUnderAgeOfConsentTag() {
185-
requestConfiguration.tagForUnderAgeOfConsent = NSNumber(value: tag)
186-
}
187-
if let testDevices = optTestDeviceIds() {
188-
requestConfiguration.testDeviceIdentifiers = testDevices
189-
}
190-
if let sameAppKey = optBool("sameAppKey") {
191-
requestConfiguration.setPublisherFirstPartyIDEnabled(sameAppKey)
192-
}
193-
if let
194-
publisherFirstPartyIDEnabled = optBool("publisherFirstPartyIDEnabled") {
195-
requestConfiguration.setPublisherFirstPartyIDEnabled(publisherFirstPartyIDEnabled)
196-
}
197-
198-
resolve()
199-
}
200-
}
201-
202-
class AMBCoreAd: NSObject {
203-
static var ads = [String: AMBCoreAd]()
204-
205-
let id: String
206-
let adUnitId: String
207-
let adRequest: Request
208-
209-
init(id: String, adUnitId: String, adRequest: Request) {
210-
self.id = id
211-
self.adUnitId = adUnitId
212-
self.adRequest = adRequest
213-
214-
super.init()
215-
216-
AMBCoreAd.ads[id] = self
217-
}
218-
219-
convenience init?(_ ctx: AMBCoreContext) {
220-
guard let id = ctx.optId(),
221-
let adUnitId = ctx.optAdUnitID()
222-
else {
223-
return nil
224-
}
225-
self.init(id: id, adUnitId: adUnitId, adRequest: ctx.optRequest())
226-
}
227-
228-
deinit {
229-
let key = self.id
230-
DispatchQueue.main.async {
231-
AMBCoreAd.ads.removeValue(forKey: key)
232-
}
233-
}
234-
}
235-
236-
class AMBBannerPlaceholder: UIView {}

‎packages/cordova/src/ios/AMBInterstitial.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AMBInterstitial: AMBAdBase, FullScreenContentDelegate {
1515
clear()
1616

1717
InterstitialAd.load(
18-
withAdUnitID: adUnitId,
18+
with: adUnitId,
1919
request: adRequest,
2020
completionHandler: { ad, error in
2121
if error != nil {
@@ -34,7 +34,7 @@ class AMBInterstitial: AMBAdBase, FullScreenContentDelegate {
3434
}
3535

3636
override func show(_ ctx: AMBContext) {
37-
mAd?.present(fromRootViewController: plugin.viewController)
37+
mAd?.present(from: plugin.viewController)
3838
ctx.resolve()
3939
}
4040

‎packages/cordova/src/ios/AMBPlugin.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AMBPlugin: CDVPlugin {
5959
@objc func start(_ command: CDVInvokedUrlCommand) {
6060
let ctx = AMBContext(command)
6161
MobileAds.shared.start(completionHandler: { _ in
62-
ctx.resolve(["version": GetStringFromVersionNumber(MobileAds.shared.versionNumber)])
62+
ctx.resolve(["version": GADGetStringFromVersionNumber(MobileAds.shared.versionNumber)])
6363
})
6464
}
6565

‎packages/cordova/src/ios/AMBRewarded.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AMBRewarded: AMBAdBase, FullScreenContentDelegate {
1414
override func load(_ ctx: AMBContext) {
1515
clear()
1616

17-
RewardedAd.load(withAdUnitID: adUnitId, request: adRequest, completionHandler: { ad, error in
17+
RewardedAd.load(with: adUnitId, request: adRequest, completionHandler: { ad, error in
1818
if error != nil {
1919
self.emit(AMBEvents.adLoadFail, error!)
2020

@@ -33,7 +33,7 @@ class AMBRewarded: AMBAdBase, FullScreenContentDelegate {
3333
}
3434

3535
override func show(_ ctx: AMBContext) {
36-
mAd?.present(fromRootViewController: plugin.viewController, userDidEarnRewardHandler: {
36+
mAd?.present(from: plugin.viewController, userDidEarnRewardHandler: {
3737
let reward = self.mAd!.adReward
3838
self.emit(AMBEvents.adReward, reward)
3939
})

‎packages/cordova/src/ios/AMBRewardedInterstitial.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AMBRewardedInterstitial: AMBAdBase, FullScreenContentDelegate {
1414
override func load(_ ctx: AMBContext) {
1515
clear()
1616

17-
RewardedInterstitialAd.load(withAdUnitID: adUnitId, request: adRequest, completionHandler: { ad, error in
17+
RewardedInterstitialAd.load(with: adUnitId, request: adRequest, completionHandler: { ad, error in
1818
if error != nil {
1919
self.emit(AMBEvents.adLoadFail, error!)
2020

@@ -33,7 +33,7 @@ class AMBRewardedInterstitial: AMBAdBase, FullScreenContentDelegate {
3333
}
3434

3535
override func show(_ ctx: AMBContext) {
36-
mAd?.present(fromRootViewController: plugin.viewController, userDidEarnRewardHandler: {
36+
mAd?.present(from: plugin.viewController, userDidEarnRewardHandler: {
3737
let reward = self.mAd!.adReward
3838
self.emit(AMBEvents.adReward, reward)
3939
})

0 commit comments

Comments
 (0)