Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Swift 6 in Native ads samples #491

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Select an Xcode version
# 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,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 @@ -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;
Expand All @@ -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;
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 @@ -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
Expand Down Expand Up @@ -273,7 +273,7 @@ extension ViewController: GADNativeAdLoaderDelegate {
}

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

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