Skip to content

Commit f5d131e

Browse files
malandr2copybara-github
authored andcommitted
Fixed Swift Concurrency runtime errors
PiperOrigin-RevId: 850049939
1 parent 25ae32d commit f5d131e

File tree

13 files changed

+76
-42
lines changed

13 files changed

+76
-42
lines changed

Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/GoogleMobileAdsConsentManager.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,7 +52,10 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

5861
Task { @MainActor in

Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/ViewController.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,15 @@ class ViewController: UIViewController, FullScreenContentDelegate {
131131
guard let self else { return }
132132

133133
loadingSpinnerWorkItem.cancel()
134+
self.loadingSpinner.stopAnimating()
134135

135-
DispatchQueue.main.async {
136-
self.loadingSpinner.stopAnimating()
137-
138-
// Animate the visibility of the game UI.
139-
UIView.animate(withDuration: 0.25) {
140-
self.gameView.alpha = 1
141-
}
142-
self.startNewGame()
136+
// Animate the visibility of the game UI.
137+
UIView.animate(withDuration: 0.25) {
138+
self.gameView.alpha = 1
143139
}
144140

141+
self.startNewGame()
142+
145143
if let consentError {
146144
// Consent gathering failed.
147145
print("Error: \(consentError.localizedDescription)")

Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

Swift/admob/AppOpenExample/AppOpenExample/GoogleMobileAdsConsentManager.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,7 +52,10 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

5861
Task { @MainActor in

Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GoogleMobileAdsConsentManager: NSObject {
4141
/// consent form if necessary.
4242
func gatherConsent(
4343
from viewController: UIViewController? = nil,
44-
consentGatheringComplete: @escaping (Error?) -> Void
44+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4545
) {
4646
let parameters = RequestParameters()
4747

@@ -56,10 +56,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5656
requestConsentError in
5757
// [START_EXCLUDE]
5858
guard requestConsentError == nil else {
59-
return consentGatheringComplete(requestConsentError)
59+
Task { @MainActor in
60+
consentGatheringComplete(requestConsentError)
61+
}
62+
return
6063
}
6164

62-
Task {
65+
Task { @MainActor in
6366
do {
6467
// [START load_and_present_consent_form]
6568
try await ConsentForm.loadAndPresentIfRequired(from: viewController)

Swift/admob/InterstitialExample/InterstitialExample/GoogleMobileAdsConsentManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoogleMobileAdsConsentManager: NSObject {
3939
/// consent form if necessary.
4040
func gatherConsent(
4141
from viewController: UIViewController? = nil,
42-
consentGatheringComplete: @escaping (Error?) -> Void
42+
consentGatheringComplete: @escaping @MainActor (Error?) -> Void
4343
) {
4444
let parameters = RequestParameters()
4545

@@ -52,10 +52,13 @@ class GoogleMobileAdsConsentManager: NSObject {
5252
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
5353
requestConsentError in
5454
guard requestConsentError == nil else {
55-
return consentGatheringComplete(requestConsentError)
55+
Task { @MainActor in
56+
consentGatheringComplete(requestConsentError)
57+
}
58+
return
5659
}
5760

58-
Task {
61+
Task { @MainActor in
5962
do {
6063
try await ConsentForm.loadAndPresentIfRequired(from: viewController)
6164
// Consent has been gathered.

0 commit comments

Comments
 (0)