Skip to content

Commit

Permalink
Swift 6 compatibility to Swift samples
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705568273
  • Loading branch information
Justin Malandruccolo authored and copybara-github committed Dec 13, 2024
1 parent f52b944 commit fb04558
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import UserMessagingPlatform
/// 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()

Expand Down Expand Up @@ -54,7 +55,7 @@ class GoogleMobileAdsConsentManager: NSObject {
return consentGatheringComplete(requestConsentError)
}

Task { @MainActor in
Task {
do {
try await UMPConsentForm.loadAndPresentIfRequired(from: viewController)
// Consent has been gathered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ class ViewController: UIViewController {

// MARK: - GADAdLoaderDelegate

extension ViewController: GADAdLoaderDelegate {
#if swift(>=6)
extension ViewController: @preconcurrency GADAdLoaderDelegate {}
#else
extension ViewController: GADAdLoaderDelegate {}
#endif

extension ViewController {
func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) {
print("\(adLoader) failed with error: \(error.localizedDescription)")
refreshAdButton.isEnabled = true
Expand All @@ -242,8 +247,13 @@ extension ViewController: GADAdLoaderDelegate {

// MARK: - GADNativeAdLoaderDelegate

extension ViewController: GADNativeAdLoaderDelegate {
#if swift(>=6)
extension ViewController: @preconcurrency GADNativeAdLoaderDelegate {}
#else
extension ViewController: GADNativeAdLoaderDelegate {}
#endif

extension ViewController {
func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
print("Received native ad: \(nativeAd)")
refreshAdButton.isEnabled = true
Expand Down Expand Up @@ -323,8 +333,7 @@ extension ViewController: GADNativeAdLoaderDelegate {
}

// MARK: - GADCustomNativeAdLoaderDelegate

extension ViewController: GADCustomNativeAdLoaderDelegate {
extension ViewController: GADCustomNativeAdDelegate {
func customNativeAdFormatIDs(for adLoader: GADAdLoader) -> [String] {
return [nativeCustomFormatId]
}
Expand Down Expand Up @@ -356,16 +365,26 @@ extension ViewController: GADCustomNativeAdLoaderDelegate {
}

// MARK: - GADVideoControllerDelegate implementation
extension ViewController: GADVideoControllerDelegate {
#if swift(>=6)
extension ViewController: @preconcurrency GADVideoControllerDelegate {}
#else
extension ViewController: GADVideoControllerDelegate {}
#endif

extension ViewController {
func videoControllerDidEndVideoPlayback(_ videoController: GADVideoController) {
videoStatusLabel.text = "Video playback has ended."
}
}

// MARK: - GADNativeAdDelegate implementation
extension ViewController: GADNativeAdDelegate {
#if swift(>=6)
extension ViewController: @preconcurrency GADNativeAdDelegate {}
#else
extension ViewController: GADNativeAdDelegate {}
#endif

extension ViewController {
func nativeAdDidRecordClick(_ nativeAd: GADNativeAd) {
print("\(#function) called")
}
Expand Down

0 comments on commit fb04558

Please sign in to comment.