From 8f158fe40f9773fdf5327ce357715f3a8cd91fda Mon Sep 17 00:00:00 2001 From: Justin Malandruccolo Date: Thu, 12 Dec 2024 11:14:11 -0800 Subject: [PATCH] Swift 6 compatibility to Swift samples PiperOrigin-RevId: 705568273 --- .github/workflows/build.yml | 18 ++++++------ .../project.pbxproj | 4 +-- .../AppOpenAdManager.swift | 1 + .../GoogleMobileAdsConsentManager.swift | 4 +-- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 2 +- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../MySimpleNativeAdView.swift | 28 ++++++++++--------- .../ViewController.swift | 10 +++---- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../ViewController.swift | 4 +-- .../project.pbxproj | 4 +-- .../GameViewController.swift | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../ViewController.swift | 4 +-- .../AppOpenExample.xcodeproj/project.pbxproj | 4 +-- .../AppOpenExample/AppOpenAdManager.swift | 1 + .../GoogleMobileAdsConsentManager.swift | 4 +-- .../BannerExample.xcodeproj/project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../BannerExample/ViewController.swift | 7 +++-- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../ViewController.swift | 8 +++--- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../project.pbxproj | 4 +-- .../GoogleMobileAdsConsentManager.swift | 4 +-- .../SwiftUIDemo.xcodeproj/project.pbxproj | 4 +-- .../Banner/BannerContentView.swift | 1 + .../Interstitial/InterstitialViewModel.swift | 3 +- .../RewardedInterstitialViewModel.swift | 3 +- .../Rewarded/RewardedContentView.swift | 4 +-- .../Rewarded/RewardedViewModel.swift | 3 +- .../GoogleMobileAdsConsentManager.swift | 2 +- .../Supporting-Files/Menu/MenuItem.swift | 5 ++-- 42 files changed, 107 insertions(+), 97 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56e39a68..01b35bf0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,22 +17,22 @@ jobs: strategy: fail-fast: false matrix: - regex: - - "Objective-C/advanced" - - "Swift/advanced" - - "Objective-C/admob" - - "Swift/admob" - - "Objective-C/admanager" - - "Swift/admanager" + include: + - { regex: "Objective-C/advanced", xcode_version: "15.3" } + - { regex: "Swift/advanced", xcode_version: "16.0" } + - { regex: "Objective-C/admob", xcode_version: "15.3" } + - { regex: "Swift/admob", xcode_version: "16.0" } + - { regex: "Objective-C/admanager", xcode_version: "15.3" } + - { regex: "Swift/admanager", xcode_version: "16.0" } steps: - name: Clone Repo uses: actions/checkout@v1 - - name: Select the Google Mobile Ads SDK minimum Xcode version (15.3) + - name: # Available Xcode versions: # https://github.com/actions/runner-images/blob/main/images/macos/toolsets/toolset-14.json run: | - sudo xcode-select -s /Applications/Xcode_15.3.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer echo "Selected Xcode version:" /usr/bin/xcodebuild -version diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample.xcodeproj/project.pbxproj index 47299b7d..f7d17c93 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample.xcodeproj/project.pbxproj @@ -327,7 +327,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.AdManagerAppOpenExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -360,7 +360,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.AdManagerAppOpenExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift index 44b2e243..7bd5b6c7 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift @@ -22,6 +22,7 @@ protocol AppOpenAdManagerDelegate: AnyObject { func appOpenAdManagerAdDidComplete(_ appOpenAdManager: AppOpenAdManager) } +@MainActor class AppOpenAdManager: NSObject { /// Ad references in the app open beta will time out after four hours, /// but this time limit may change in future beta versions. For details, see: diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample.xcodeproj/project.pbxproj index 800dc552..73d97dfd 100644 --- a/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample.xcodeproj/project.pbxproj @@ -285,7 +285,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -306,7 +306,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..adb615da 100644 --- a/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() diff --git a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample.xcodeproj/project.pbxproj index 44a6b88d..b10161e9 100644 --- a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample.xcodeproj/project.pbxproj @@ -312,7 +312,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.AdManagerCustomRenderingExample; PRODUCT_NAME = AdManagerCustomRenderingExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -331,7 +331,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.AdManagerCustomRenderingExample; PRODUCT_NAME = AdManagerCustomRenderingExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/MySimpleNativeAdView.swift b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/MySimpleNativeAdView.swift index 31b91f82..1ce6dfd8 100644 --- a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/MySimpleNativeAdView.swift +++ b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/MySimpleNativeAdView.swift @@ -45,19 +45,21 @@ class MySimpleNativeAdView: UIView { override func awakeFromNib() { super.awakeFromNib() - // Enable clicks on the main image. - mainPlaceholder.addGestureRecognizer( - UITapGestureRecognizer( - target: self, - action: #selector(performClickOnMainImage(_:)))) - mainPlaceholder.isUserInteractionEnabled = true - - // Enable clicks on AdChoices. - adChoicesView.addGestureRecognizer( - UITapGestureRecognizer( - target: self, - action: #selector(performClickOnAdChoices(_:)))) - adChoicesView.isUserInteractionEnabled = true + DispatchQueue.main.async { + // Enable clicks on the main image. + self.mainPlaceholder.addGestureRecognizer( + UITapGestureRecognizer( + target: self, + action: #selector(self.performClickOnMainImage(_:)))) + self.mainPlaceholder.isUserInteractionEnabled = true + + // Enable clicks on AdChoices. + self.adChoicesView.addGestureRecognizer( + UITapGestureRecognizer( + target: self, + action: #selector(self.performClickOnAdChoices(_:)))) + self.adChoicesView.isUserInteractionEnabled = true + } } @objc func performClickOnMainImage(_ sender: UITapGestureRecognizer!) { diff --git a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/ViewController.swift b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/ViewController.swift index 0e528462..3674bd97 100644 --- a/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/ViewController.swift +++ b/Swift/admanager/AdManagerCustomRenderingExample/AdManagerCustomRenderingExample/ViewController.swift @@ -232,7 +232,7 @@ class ViewController: UIViewController { // MARK: - GADAdLoaderDelegate -extension ViewController: GADAdLoaderDelegate { +extension ViewController: @preconcurrency GADAdLoaderDelegate { func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) { print("\(adLoader) failed with error: \(error.localizedDescription)") @@ -242,7 +242,7 @@ extension ViewController: GADAdLoaderDelegate { // MARK: - GADNativeAdLoaderDelegate -extension ViewController: GADNativeAdLoaderDelegate { +extension ViewController: @preconcurrency GADNativeAdLoaderDelegate { func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) { print("Received native ad: \(nativeAd)") @@ -324,7 +324,7 @@ extension ViewController: GADNativeAdLoaderDelegate { // MARK: - GADCustomNativeAdLoaderDelegate -extension ViewController: GADCustomNativeAdLoaderDelegate { +extension ViewController: @preconcurrency GADCustomNativeAdLoaderDelegate { func customNativeAdFormatIDs(for adLoader: GADAdLoader) -> [String] { return [nativeCustomFormatId] } @@ -356,7 +356,7 @@ extension ViewController: GADCustomNativeAdLoaderDelegate { } // MARK: - GADVideoControllerDelegate implementation -extension ViewController: GADVideoControllerDelegate { +extension ViewController: @preconcurrency GADVideoControllerDelegate { func videoControllerDidEndVideoPlayback(_ videoController: GADVideoController) { videoStatusLabel.text = "Video playback has ended." @@ -364,7 +364,7 @@ extension ViewController: GADVideoControllerDelegate { } // MARK: - GADNativeAdDelegate implementation -extension ViewController: GADNativeAdDelegate { +extension ViewController: @preconcurrency GADNativeAdDelegate { func nativeAdDidRecordClick(_ nativeAd: GADNativeAd) { print("\(#function) called") diff --git a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample.xcodeproj/project.pbxproj index 9c1e33c7..cb890a3e 100644 --- a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample.xcodeproj/project.pbxproj @@ -284,7 +284,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -304,7 +304,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/ViewController.swift b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/ViewController.swift index cace905c..f04a59b2 100644 --- a/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/ViewController.swift +++ b/Swift/admanager/AdManagerInterstitialExample/AdManagerInterstitialExample/ViewController.swift @@ -14,10 +14,10 @@ // limitations under the License. // -import GoogleMobileAds +@preconcurrency import GoogleMobileAds import UIKit -class ViewController: UIViewController, GADFullScreenContentDelegate { +class ViewController: UIViewController, @preconcurrency GADFullScreenContentDelegate { enum GameState: NSInteger { case notStarted diff --git a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample.xcodeproj/project.pbxproj index 32be84ed..a669c8c9 100644 --- a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample.xcodeproj/project.pbxproj @@ -316,7 +316,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -341,7 +341,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GameViewController.swift b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GameViewController.swift index 4f2f0d05..fe2c1e40 100644 --- a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GameViewController.swift +++ b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GameViewController.swift @@ -14,10 +14,10 @@ // limitations under the License. // -import GoogleMobileAds +@preconcurrency import GoogleMobileAds import UIKit -class GameViewController: UIViewController, GADFullScreenContentDelegate { +class GameViewController: UIViewController, @preconcurrency GADFullScreenContentDelegate { private enum GameState: Int { case notStarted diff --git a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerRewardedInterstitialExample/AdManagerRewardedInterstitialExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample.xcodeproj/project.pbxproj b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample.xcodeproj/project.pbxproj index 072de27f..0e45a85b 100644 --- a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample.xcodeproj/project.pbxproj +++ b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample.xcodeproj/project.pbxproj @@ -283,7 +283,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedVideoExample; PRODUCT_NAME = AdManagerRewardedVideoExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -302,7 +302,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedVideoExample; PRODUCT_NAME = AdManagerRewardedVideoExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/GoogleMobileAdsConsentManager.swift b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/ViewController.swift b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/ViewController.swift index 319ce2dc..2eccb7dc 100644 --- a/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/ViewController.swift +++ b/Swift/admanager/AdManagerRewardedVideoExample/AdManagerRewardedVideoExample/ViewController.swift @@ -14,10 +14,10 @@ // limitations under the License. // -import GoogleMobileAds +@preconcurrency import GoogleMobileAds import UIKit -class ViewController: UIViewController, GADFullScreenContentDelegate { +class ViewController: UIViewController, @preconcurrency GADFullScreenContentDelegate { enum GameState: NSInteger { case notStarted diff --git a/Swift/admob/AppOpenExample/AppOpenExample.xcodeproj/project.pbxproj b/Swift/admob/AppOpenExample/AppOpenExample.xcodeproj/project.pbxproj index 693259b6..dab26fff 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample.xcodeproj/project.pbxproj +++ b/Swift/admob/AppOpenExample/AppOpenExample.xcodeproj/project.pbxproj @@ -326,7 +326,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.AppOpenExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -358,7 +358,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.AppOpenExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift b/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift index 9df041df..d19c398f 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift +++ b/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift @@ -22,6 +22,7 @@ protocol AppOpenAdManagerDelegate: AnyObject { func appOpenAdManagerAdDidComplete(_ appOpenAdManager: AppOpenAdManager) } +@MainActor class AppOpenAdManager: NSObject { /// Ad references in the app open beta will time out after four hours, /// but this time limit may change in future beta versions. For details, see: diff --git a/Swift/admob/AppOpenExample/AppOpenExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/AppOpenExample/AppOpenExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/AppOpenExample/AppOpenExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admob/BannerExample/BannerExample.xcodeproj/project.pbxproj b/Swift/admob/BannerExample/BannerExample.xcodeproj/project.pbxproj index 481aa648..61d9837d 100644 --- a/Swift/admob/BannerExample/BannerExample.xcodeproj/project.pbxproj +++ b/Swift/admob/BannerExample/BannerExample.xcodeproj/project.pbxproj @@ -291,7 +291,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.BannerExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -311,7 +311,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.BannerExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift index 34141bc3..24bc99f5 100644 --- a/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/BannerExample/BannerExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -56,7 +56,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { // [START load_and_present_consent_form] try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) diff --git a/Swift/admob/BannerExample/BannerExample/ViewController.swift b/Swift/admob/BannerExample/BannerExample/ViewController.swift index 71c36eaf..9e1db5f8 100644 --- a/Swift/admob/BannerExample/BannerExample/ViewController.swift +++ b/Swift/admob/BannerExample/BannerExample/ViewController.swift @@ -17,7 +17,7 @@ import GoogleMobileAds import UIKit -class ViewController: UIViewController, GADBannerViewDelegate { +class ViewController: UIViewController { @IBOutlet weak var bannerView: GADBannerView! @IBOutlet weak var privacySettingsButton: UIBarButtonItem! @@ -134,9 +134,11 @@ class ViewController: UIViewController, GADBannerViewDelegate { bannerView.load(GADRequest()) } +} - // MARK: - GADBannerViewDelegate methods +// MARK: - GADBannerViewDelegate methods +extension ViewController: @preconcurrency GADBannerViewDelegate { func bannerViewDidReceiveAd(_ bannerView: GADBannerView) { print(#function) } @@ -164,5 +166,4 @@ class ViewController: UIViewController, GADBannerViewDelegate { func bannerViewDidDismissScreen(_ bannerView: GADBannerView) { print(#function) } - } diff --git a/Swift/admob/InterstitialExample/InterstitialExample.xcodeproj/project.pbxproj b/Swift/admob/InterstitialExample/InterstitialExample.xcodeproj/project.pbxproj index 7fb08bf7..e75d5ca9 100644 --- a/Swift/admob/InterstitialExample/InterstitialExample.xcodeproj/project.pbxproj +++ b/Swift/admob/InterstitialExample/InterstitialExample.xcodeproj/project.pbxproj @@ -292,7 +292,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -312,7 +312,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.ads.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admob/InterstitialExample/InterstitialExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/InterstitialExample/InterstitialExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admob/InterstitialExample/InterstitialExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/InterstitialExample/InterstitialExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample.xcodeproj/project.pbxproj b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample.xcodeproj/project.pbxproj index b179152f..8b474fe2 100644 --- a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample.xcodeproj/project.pbxproj +++ b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample.xcodeproj/project.pbxproj @@ -294,7 +294,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.NativeAdvancedExample; PRODUCT_NAME = NativeAdvancedExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -314,7 +314,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.NativeAdvancedExample; PRODUCT_NAME = NativeAdvancedExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/ViewController.swift b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/ViewController.swift index 59e2a168..31cc57a0 100644 --- a/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/ViewController.swift +++ b/Swift/admob/NativeAdvancedExample/NativeAdvancedExample/ViewController.swift @@ -184,21 +184,21 @@ class ViewController: UIViewController { } } -extension ViewController: GADVideoControllerDelegate { +extension ViewController: @preconcurrency GADVideoControllerDelegate { func videoControllerDidEndVideoPlayback(_ videoController: GADVideoController) { videoStatusLabel.text = "Video playback has ended." } } -extension ViewController: GADAdLoaderDelegate { +extension ViewController: @preconcurrency GADAdLoaderDelegate { func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) { print("\(adLoader) failed with error: \(error.localizedDescription)") refreshAdButton.isEnabled = true } } -extension ViewController: GADNativeAdLoaderDelegate { +extension ViewController: @preconcurrency GADNativeAdLoaderDelegate { func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) { refreshAdButton.isEnabled = true @@ -273,7 +273,7 @@ extension ViewController: GADNativeAdLoaderDelegate { } // MARK: - GADNativeAdDelegate implementation -extension ViewController: GADNativeAdDelegate { +extension ViewController: @preconcurrency GADNativeAdDelegate { func nativeAdDidRecordClick(_ nativeAd: GADNativeAd) { print("\(#function) called") diff --git a/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample.xcodeproj/project.pbxproj b/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample.xcodeproj/project.pbxproj index 8aa29892..3e15bd6a 100644 --- a/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample.xcodeproj/project.pbxproj +++ b/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample.xcodeproj/project.pbxproj @@ -313,7 +313,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedInterstitialExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -334,7 +334,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedInterstitialExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/RewardedInterstitialExample/RewardedInterstitialExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/admob/RewardedVideoExample/RewardedVideoExample.xcodeproj/project.pbxproj b/Swift/admob/RewardedVideoExample/RewardedVideoExample.xcodeproj/project.pbxproj index 49bfa644..4c70e885 100644 --- a/Swift/admob/RewardedVideoExample/RewardedVideoExample.xcodeproj/project.pbxproj +++ b/Swift/admob/RewardedVideoExample/RewardedVideoExample.xcodeproj/project.pbxproj @@ -291,7 +291,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedVideoExample; PRODUCT_NAME = RewardedVideoExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -310,7 +310,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.ads.RewardedVideoExample; PRODUCT_NAME = RewardedVideoExample; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; diff --git a/Swift/admob/RewardedVideoExample/RewardedVideoExample/GoogleMobileAdsConsentManager.swift b/Swift/admob/RewardedVideoExample/RewardedVideoExample/GoogleMobileAdsConsentManager.swift index 091ee3d6..7ad6c94c 100644 --- a/Swift/admob/RewardedVideoExample/RewardedVideoExample/GoogleMobileAdsConsentManager.swift +++ b/Swift/admob/RewardedVideoExample/RewardedVideoExample/GoogleMobileAdsConsentManager.swift @@ -22,7 +22,7 @@ import UserMessagingPlatform /// IAB Certified consent management platform) as one solution to capture /// consent for users in GDPR impacted countries. This is an example and /// you can choose another consent management platform to capture consent. - +@MainActor class GoogleMobileAdsConsentManager: NSObject { static let shared = GoogleMobileAdsConsentManager() @@ -54,7 +54,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { try await UMPConsentForm.loadAndPresentIfRequired(from: viewController) // Consent has been gathered. diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo.xcodeproj/project.pbxproj b/Swift/advanced/SwiftUIDemo/SwiftUIDemo.xcodeproj/project.pbxproj index e2d71e91..39ec22de 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo.xcodeproj/project.pbxproj +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo.xcodeproj/project.pbxproj @@ -402,7 +402,7 @@ SDKROOT = iphoneos; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -438,7 +438,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Banner/BannerContentView.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Banner/BannerContentView.swift index b011a548..ec99a314 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Banner/BannerContentView.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Banner/BannerContentView.swift @@ -55,6 +55,7 @@ private struct BannerView: UIViewRepresentable { // [START create_banner] class BannerCoordinator: NSObject, GADBannerViewDelegate { + @MainActor private(set) lazy var bannerView: GADBannerView = { let banner = GADBannerView(adSize: parent.adSize) // [START load_ad] diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Interstitial/InterstitialViewModel.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Interstitial/InterstitialViewModel.swift index 71bf5d79..c9a0decd 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Interstitial/InterstitialViewModel.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Interstitial/InterstitialViewModel.swift @@ -15,11 +15,12 @@ // // [START load_ad] -import GoogleMobileAds +@preconcurrency import GoogleMobileAds class InterstitialViewModel: NSObject, GADFullScreenContentDelegate { private var interstitialAd: GADInterstitialAd? + @MainActor func loadAd() async { do { interstitialAd = try await GADInterstitialAd.load( diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded-Interstitial/RewardedInterstitialViewModel.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded-Interstitial/RewardedInterstitialViewModel.swift index 6ac99732..030dbde1 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded-Interstitial/RewardedInterstitialViewModel.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded-Interstitial/RewardedInterstitialViewModel.swift @@ -15,7 +15,7 @@ // // [START load_ad] -import GoogleMobileAds +@preconcurrency import GoogleMobileAds class RewardedInterstitialViewModel: NSObject, ObservableObject, GADFullScreenContentDelegate @@ -23,6 +23,7 @@ class RewardedInterstitialViewModel: NSObject, ObservableObject, @Published var coins = 0 private var rewardedInterstitialAd: GADRewardedInterstitialAd? + @MainActor func loadAd() async { do { rewardedInterstitialAd = try await GADRewardedInterstitialAd.load( diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedContentView.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedContentView.swift index 9cf707f8..43680bf9 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedContentView.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedContentView.swift @@ -14,7 +14,7 @@ // limitations under the License. // -import GoogleMobileAds +@preconcurrency import GoogleMobileAds import SwiftUI struct RewardedContentView: View { @@ -77,7 +77,7 @@ struct RewardedContentView: View { private func startNewGame() { countdownTimer.start() - Task { + Task { @MainActor in await viewModel.loadAd() } } diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedViewModel.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedViewModel.swift index a498b416..83ee07e8 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedViewModel.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Rewarded/RewardedViewModel.swift @@ -15,12 +15,13 @@ // // [START load_ad] -import GoogleMobileAds +@preconcurrency import GoogleMobileAds class RewardedViewModel: NSObject, ObservableObject, GADFullScreenContentDelegate { @Published var coins = 0 private var rewardedAd: GADRewardedAd? + @MainActor func loadAd() async { do { rewardedAd = try await GADRewardedAd.load( diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift index ca2180f9..0b862abb 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/GoogleMobileAdsConsentManager.swift @@ -55,7 +55,7 @@ class GoogleMobileAdsConsentManager: NSObject { return consentGatheringComplete(requestConsentError) } - Task { @MainActor in + Task { do { // [START load_and_present_consent_form] try await UMPConsentForm.loadAndPresentIfRequired(from: nil) diff --git a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuItem.swift b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuItem.swift index 617c9314..162fd392 100644 --- a/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuItem.swift +++ b/Swift/advanced/SwiftUIDemo/SwiftUIDemo/Supporting-Files/Menu/MenuItem.swift @@ -1,7 +1,8 @@ import Foundation import SwiftUI -enum MenuItem: String, Identifiable { +@MainActor +enum MenuItem: String, @preconcurrency Identifiable { var id: Self { self } case banner = "Banner" @@ -16,7 +17,7 @@ enum MenuItem: String, Identifiable { } extension MenuItem { - @ViewBuilder + @MainActor @ViewBuilder private func viewForType() -> some View { switch self { case .banner: