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 12, 2024
1 parent f52b944 commit 8f158fe
Show file tree
Hide file tree
Showing 42 changed files with 107 additions and 97 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 @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

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 @@ -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()

Expand Down Expand Up @@ -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.
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,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)")
Expand All @@ -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)")
Expand Down Expand Up @@ -324,7 +324,7 @@ extension ViewController: GADNativeAdLoaderDelegate {

// MARK: - GADCustomNativeAdLoaderDelegate

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

// MARK: - GADVideoControllerDelegate implementation
extension ViewController: GADVideoControllerDelegate {
extension ViewController: @preconcurrency GADVideoControllerDelegate {

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

// MARK: - GADNativeAdDelegate implementation
extension ViewController: GADNativeAdDelegate {
extension ViewController: @preconcurrency GADNativeAdDelegate {

func nativeAdDidRecordClick(_ nativeAd: GADNativeAd) {
print("\(#function) called")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 8f158fe

Please sign in to comment.