From b7e8ec13793d54a9cc59557ec9b42ea4894f35d6 Mon Sep 17 00:00:00 2001 From: mobile-ads-github Date: Wed, 30 Aug 2023 16:35:18 +0200 Subject: [PATCH] Update changlelog and public sample --- .../project.pbxproj | 52 ++++++----- .../YandexMobileAdsExample/AppDelegate.swift | 15 ++- .../AdMob/AdMobNativeAdView.swift | 16 ++-- .../AppOpenAd/AppOpenAdController.swift | 93 +++++++++++++++++++ .../AppOpenAdControllerDelegate.swift | 13 +++ .../AppOpenAd/AppOpenAdViewController.swift | 92 ++++-------------- .../InterstitialAdViewController.swift | 22 ++--- .../Rewarded/RewardedAdViewController.swift | 24 ++--- .../Yandex/YandexAdsViewController.swift | 2 +- changelog/mobileads/CHANGELOG.md | 5 +- 10 files changed, 199 insertions(+), 135 deletions(-) create mode 100644 Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdController.swift create mode 100644 Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdControllerDelegate.swift diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample.xcodeproj/project.pbxproj b/Examples/YandexMobileAdsExample/YandexMobileAdsExample.xcodeproj/project.pbxproj index c745762..e210081 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample.xcodeproj/project.pbxproj +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample.xcodeproj/project.pbxproj @@ -52,8 +52,8 @@ 46C354A0282560FE00832C7C /* IronSourceRewardedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3549D282560FE00832C7C /* IronSourceRewardedViewController.swift */; }; 46C354A1282560FE00832C7C /* IronSourceInterstitialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3549E282560FE00832C7C /* IronSourceInterstitialViewController.swift */; }; 46C354A2282560FE00832C7C /* IronSourceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3549F282560FE00832C7C /* IronSourceManager.swift */; }; - 70011FE6B068EC271A1051CB /* libPods-YandexMobileAdsExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A35F1D3A95F5CC1C05B0ED57 /* libPods-YandexMobileAdsExample.a */; }; B394AC8627A868DB00D92CD9 /* AdPlayerErrorConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B394AC8527A868DB00D92CD9 /* AdPlayerErrorConverter.swift */; }; + D875A622E1AC90D14FC62770 /* libPods-YandexMobileAdsExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BF35ACE34CE63F32697C83A /* libPods-YandexMobileAdsExample.a */; }; DE0C2CBE2A65760900A84D00 /* NativeTemplateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0C2CBD2A65760900A84D00 /* NativeTemplateViewController.swift */; }; DE0C2CC02A66245700A84D00 /* NativeCustomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0C2CBF2A66245700A84D00 /* NativeCustomViewController.swift */; }; DE0C2CC22A671FF500A84D00 /* NativeCustomAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0C2CC12A671FF500A84D00 /* NativeCustomAdView.swift */; }; @@ -69,6 +69,8 @@ DEC81AE82A54D8DE008FE935 /* InlineBannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC81AE72A54D8DE008FE935 /* InlineBannerViewController.swift */; }; DEC81AEC2A55A2F6008FE935 /* RewardedAdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC81AEB2A55A2F6008FE935 /* RewardedAdViewController.swift */; }; DEC81AEE2A55ADEC008FE935 /* InterstitialAdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC81AED2A55ADEC008FE935 /* InterstitialAdViewController.swift */; }; + F7613F2C2A9E384F0024A580 /* AppOpenAdController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7613F2B2A9E384F0024A580 /* AppOpenAdController.swift */; }; + F7613F2E2A9E3BF90024A580 /* AppOpenAdControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7613F2D2A9E3BF90024A580 /* AppOpenAdControllerDelegate.swift */; }; F7D8B4D32A97B41F00E7A40D /* AppOpenAdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7D8B4D22A97B41F00E7A40D /* AppOpenAdViewController.swift */; }; /* End PBXBuildFile section */ @@ -118,11 +120,12 @@ 149931832722BD94005D2E87 /* AdFoxNativeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdFoxNativeViewController.swift; sourceTree = ""; }; 149931872722C423005D2E87 /* AdFoxBannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdFoxBannerViewController.swift; sourceTree = ""; }; 1499318A2722CD44005D2E87 /* AdFoxInterstitialViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdFoxInterstitialViewController.swift; sourceTree = ""; }; + 1E90A095D570D172ED5B43BF /* Pods-YandexMobileAdsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexMobileAdsExample.release.xcconfig"; path = "Target Support Files/Pods-YandexMobileAdsExample/Pods-YandexMobileAdsExample.release.xcconfig"; sourceTree = ""; }; 46C3549D282560FE00832C7C /* IronSourceRewardedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IronSourceRewardedViewController.swift; sourceTree = ""; }; 46C3549E282560FE00832C7C /* IronSourceInterstitialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IronSourceInterstitialViewController.swift; sourceTree = ""; }; 46C3549F282560FE00832C7C /* IronSourceManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IronSourceManager.swift; sourceTree = ""; }; - 9722EABB876EC1FBC865DDBE /* Pods-YandexMobileAdsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexMobileAdsExample.release.xcconfig"; path = "Target Support Files/Pods-YandexMobileAdsExample/Pods-YandexMobileAdsExample.release.xcconfig"; sourceTree = ""; }; - A35F1D3A95F5CC1C05B0ED57 /* libPods-YandexMobileAdsExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-YandexMobileAdsExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4D78122160DD5201E335FB9A /* Pods-YandexMobileAdsExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexMobileAdsExample.debug.xcconfig"; path = "Target Support Files/Pods-YandexMobileAdsExample/Pods-YandexMobileAdsExample.debug.xcconfig"; sourceTree = ""; }; + 5BF35ACE34CE63F32697C83A /* libPods-YandexMobileAdsExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-YandexMobileAdsExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; B394AC8527A868DB00D92CD9 /* AdPlayerErrorConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdPlayerErrorConverter.swift; sourceTree = ""; }; DE0C2CBD2A65760900A84D00 /* NativeTemplateViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeTemplateViewController.swift; sourceTree = ""; }; DE0C2CBF2A66245700A84D00 /* NativeCustomViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeCustomViewController.swift; sourceTree = ""; }; @@ -139,7 +142,8 @@ DEC81AE72A54D8DE008FE935 /* InlineBannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineBannerViewController.swift; sourceTree = ""; }; DEC81AEB2A55A2F6008FE935 /* RewardedAdViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RewardedAdViewController.swift; sourceTree = ""; }; DEC81AED2A55ADEC008FE935 /* InterstitialAdViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialAdViewController.swift; sourceTree = ""; }; - EA2B7BC1DE6EF14C5B13E9F5 /* Pods-YandexMobileAdsExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexMobileAdsExample.debug.xcconfig"; path = "Target Support Files/Pods-YandexMobileAdsExample/Pods-YandexMobileAdsExample.debug.xcconfig"; sourceTree = ""; }; + F7613F2B2A9E384F0024A580 /* AppOpenAdController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppOpenAdController.swift; sourceTree = ""; }; + F7613F2D2A9E3BF90024A580 /* AppOpenAdControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppOpenAdControllerDelegate.swift; sourceTree = ""; }; F7D8B4D22A97B41F00E7A40D /* AppOpenAdViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppOpenAdViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -148,7 +152,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 70011FE6B068EC271A1051CB /* libPods-YandexMobileAdsExample.a in Frameworks */, + D875A622E1AC90D14FC62770 /* libPods-YandexMobileAdsExample.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -299,7 +303,7 @@ 1467E351271EA91500DF104A /* YandexMobileAdsExample */, 1467E350271EA91500DF104A /* Products */, 79BD0E00D8B73D2FF9E77E93 /* Pods */, - 2C60026A65F390098BEA71D6 /* Frameworks */, + 5E36114E6565E861DBB72B75 /* Frameworks */, ); sourceTree = ""; }; @@ -426,14 +430,6 @@ path = Adfox; sourceTree = ""; }; - 2C60026A65F390098BEA71D6 /* Frameworks */ = { - isa = PBXGroup; - children = ( - A35F1D3A95F5CC1C05B0ED57 /* libPods-YandexMobileAdsExample.a */, - ); - name = Frameworks; - sourceTree = ""; - }; 46C3549C282560FE00832C7C /* IronSource */ = { isa = PBXGroup; children = ( @@ -444,11 +440,19 @@ path = IronSource; sourceTree = ""; }; + 5E36114E6565E861DBB72B75 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5BF35ACE34CE63F32697C83A /* libPods-YandexMobileAdsExample.a */, + ); + name = Frameworks; + sourceTree = ""; + }; 79BD0E00D8B73D2FF9E77E93 /* Pods */ = { isa = PBXGroup; children = ( - EA2B7BC1DE6EF14C5B13E9F5 /* Pods-YandexMobileAdsExample.debug.xcconfig */, - 9722EABB876EC1FBC865DDBE /* Pods-YandexMobileAdsExample.release.xcconfig */, + 4D78122160DD5201E335FB9A /* Pods-YandexMobileAdsExample.debug.xcconfig */, + 1E90A095D570D172ED5B43BF /* Pods-YandexMobileAdsExample.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -457,6 +461,8 @@ isa = PBXGroup; children = ( F7D8B4D22A97B41F00E7A40D /* AppOpenAdViewController.swift */, + F7613F2B2A9E384F0024A580 /* AppOpenAdController.swift */, + F7613F2D2A9E3BF90024A580 /* AppOpenAdControllerDelegate.swift */, ); path = AppOpenAd; sourceTree = ""; @@ -468,11 +474,11 @@ isa = PBXNativeTarget; buildConfigurationList = 1467E379271EA91700DF104A /* Build configuration list for PBXNativeTarget "YandexMobileAdsExample" */; buildPhases = ( - 0774874AE61A4B3DC4B5CCEC /* [CP] Check Pods Manifest.lock */, + 12B2C11F8B81B215E323277A /* [CP] Check Pods Manifest.lock */, 1467E34B271EA91500DF104A /* Sources */, 1467E34C271EA91500DF104A /* Frameworks */, 1467E34D271EA91500DF104A /* Resources */, - 5BE131876F56185647AB5025 /* [CP] Copy Pods Resources */, + E4E9AE0924D84CE9CC90A2AD /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -531,7 +537,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0774874AE61A4B3DC4B5CCEC /* [CP] Check Pods Manifest.lock */ = { + 12B2C11F8B81B215E323277A /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -553,7 +559,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 5BE131876F56185647AB5025 /* [CP] Copy Pods Resources */ = { + E4E9AE0924D84CE9CC90A2AD /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -588,6 +594,7 @@ DE6D740C2A740E080024DA8F /* InstreamInrollsViewController.swift in Sources */, DEC81AE42A53C945008FE935 /* NavigationScreenDataSource.swift in Sources */, 46C354A0282560FE00832C7C /* IronSourceRewardedViewController.swift in Sources */, + F7613F2E2A9E3BF90024A580 /* AppOpenAdControllerDelegate.swift in Sources */, 14033FB72720457800A24D5E /* VideoAVPlayer.swift in Sources */, 14033F8927202CA800A24D5E /* AdMobRewardedViewController.swift in Sources */, 147B0BD127200D14005F4062 /* NativeAdView.swift in Sources */, @@ -633,6 +640,7 @@ 14033FBE2720457800A24D5E /* InstreamAdBinderToastDelegate.swift in Sources */, DE0C2CC22A671FF500A84D00 /* NativeCustomAdView.swift in Sources */, 147B0BCF27200D14005F4062 /* StarRatingView.swift in Sources */, + F7613F2C2A9E384F0024A580 /* AppOpenAdController.swift in Sources */, 14033FB82720457800A24D5E /* ContentPlayer.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -777,7 +785,7 @@ }; 1467E37A271EA91700DF104A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = EA2B7BC1DE6EF14C5B13E9F5 /* Pods-YandexMobileAdsExample.debug.xcconfig */; + baseConfigurationReference = 4D78122160DD5201E335FB9A /* Pods-YandexMobileAdsExample.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; @@ -805,7 +813,7 @@ }; 1467E37B271EA91700DF104A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9722EABB876EC1FBC865DDBE /* Pods-YandexMobileAdsExample.release.xcconfig */; + baseConfigurationReference = 1E90A095D570D172ED5B43BF /* Pods-YandexMobileAdsExample.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/AppDelegate.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/AppDelegate.swift index ca65825..8834731 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/AppDelegate.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/AppDelegate.swift @@ -1,21 +1,26 @@ /* - * Version for iOS © 2015–2021 YANDEX + * Version for iOS © 2015–2023 YANDEX * * You may not use this file except in compliance with the License. * You may obtain a copy of the License at https://yandex.com/legal/mobileads_sdk_agreement/ */ -import UIKit -import GoogleMobileAds +import YandexMobileAds @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + YMAMobileAds.initializeSDK() return true } + + func applicationDidBecomeActive(_ application: UIApplication) { + AppOpenAdController.shared.showAdIfAvailable(from: window) + } } diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Third-PartyMediation/AdMob/AdMobNativeAdView.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Third-PartyMediation/AdMob/AdMobNativeAdView.swift index 628c988..9be8e43 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Third-PartyMediation/AdMob/AdMobNativeAdView.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Third-PartyMediation/AdMob/AdMobNativeAdView.swift @@ -1,5 +1,5 @@ /* - * Version for iOS © 2015–2021 YANDEX + * Version for iOS © 2015–2023 YANDEX * * You may not use this file except in compliance with the License. * You may obtain a copy of the License at https://yandex.com/legal/mobileads_sdk_agreement/ @@ -15,7 +15,7 @@ class AdMobNativeAdView: GADNativeAdView { @IBOutlet weak var reviewCountLabel: UILabel! @IBOutlet weak var ratingView: StarRatingView! @IBOutlet weak var faviconImageView: UIImageView! - + private var aspectRatioConstraint: NSLayoutConstraint? func configureAssetViews() { @@ -70,24 +70,24 @@ class AdMobNativeAdView: GADNativeAdView { } } -extension AdMobNativeAdView: YMAAdMobCustomEventNativeAdView { - func nativeAgeLabel() -> UILabel! { +extension AdMobNativeAdView: YandexAdMobCustomEventNativeAdView { + func nativeAgeLabel() -> UILabel? { return ageLabel } - func nativeFaviconImageView() -> UIImageView! { + func nativeFaviconImageView() -> UIImageView? { return faviconImageView } - func nativeRatingView() -> (UIView & YMARating)! { + func nativeRatingView() -> (UIView & YMARating)? { return ratingView } - func nativeReviewCountLabel() -> UILabel! { + func nativeReviewCountLabel() -> UILabel? { return reviewCountLabel } - func nativeWarningLabel() -> UILabel! { + func nativeWarningLabel() -> UILabel? { return warningLabel } } diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdController.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdController.swift new file mode 100644 index 0000000..4ac8487 --- /dev/null +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdController.swift @@ -0,0 +1,93 @@ +/* + * Version for iOS © 2015–2023 YANDEX + * + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at https://yandex.com/legal/mobileads_sdk_agreement/ + */ + +import YandexMobileAds + +final class AppOpenAdController: NSObject { + static let shared = AppOpenAdController() + + weak var delegate: AppOpenAdControllerDelegate? + + private var appOpenAd: YMAAppOpenAd? + + private lazy var appOpenAdLoader: YMAAppOpenAdLoader = { + let loader = YMAAppOpenAdLoader() + loader.delegate = self + return loader + }() + + func loadAd() { + // Replace demo-appopenad-yandex with actual Ad Unit ID + let configuration = YMAAdRequestConfiguration(adUnitID: "demo-appopenad-yandex") + appOpenAdLoader.loadAd(with: configuration) + } + + func showAdIfAvailable(from window: UIWindow?) { + guard let viewController = window?.rootViewController else { return } + appOpenAd?.show(from: viewController) + } + + private func makeMessageDescription(_ appOpenAd: YMAAppOpenAd) -> String { + "AppOpenAd with Ad Unit ID: \(String(describing: appOpenAd.adInfo?.adUnitId))" + } +} + +// MARK: - YMAAppOpenAdDelegate + +extension AppOpenAdController: YMAAppOpenAdDelegate { + func appOpenAdDidDismiss(_ appOpenAd: YMAAppOpenAd) { + self.appOpenAd = nil + print("\(makeMessageDescription(appOpenAd)) did dismiss") + delegate?.appOpenAdControllerDidDismiss(self) + } + + func appOpenAd( + _ appOpenAd: YMAAppOpenAd, + didFailToShowWithError error: Error + ) { + self.appOpenAd = nil + print("\(makeMessageDescription(appOpenAd)) failed to show. Error: \(String(describing: error))") + delegate?.appOpenAdController(self, didFailToShowWithError: error) + } + + func appOpenAdDidShow(_ appOpenAd: YMAAppOpenAd) { + print("\(makeMessageDescription(appOpenAd)) did show") + } + + func appOpenAdDidClick(_ appOpenAd: YMAAppOpenAd) { + print("\(makeMessageDescription(appOpenAd)) did click") + } + + func appOpenAd(_ appOpenAd: YMAAppOpenAd, didTrackImpressionWith impressionData: YMAImpressionData?) { + print("\(makeMessageDescription(appOpenAd)) did track impression") + } +} + +// MARK: - YMAAppOpenAdLoaderDelegate + +extension AppOpenAdController: YMAAppOpenAdLoaderDelegate { + func appOpenAdLoader( + _ adLoader: YMAAppOpenAdLoader, + didLoad appOpenAd: YMAAppOpenAd + ) { + self.appOpenAd = appOpenAd + self.appOpenAd?.delegate = self + print("\(makeMessageDescription(appOpenAd)) did load") + delegate?.appOpenAdControllerDidLoad(self) + } + + func appOpenAdLoader( + _ adLoader: YMAAppOpenAdLoader, + didFailToLoadWithError error: YMAAdRequestError + ) { + appOpenAd = nil + let id = error.adUnitId + let error = error.error + print("Loading failed for Ad with Unit ID: \(String(describing: id)). Error: \(String(describing: error))") + delegate?.appOpenAdController(self, didFailToLoadWithError: error) + } +} diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdControllerDelegate.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdControllerDelegate.swift new file mode 100644 index 0000000..6bad160 --- /dev/null +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdControllerDelegate.swift @@ -0,0 +1,13 @@ +/* + * Version for iOS © 2015–2023 YANDEX + * + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at https://yandex.com/legal/mobileads_sdk_agreement/ + */ + +protocol AppOpenAdControllerDelegate: AnyObject { + func appOpenAdControllerDidLoad(_ appOpenAdController: AppOpenAdController) + func appOpenAdControllerDidDismiss(_ appOpenAdController: AppOpenAdController) + func appOpenAdController(_ appOpenAdController: AppOpenAdController, didFailToLoadWithError error: Error) + func appOpenAdController(_ appOpenAdController: AppOpenAdController, didFailToShowWithError error: Error) +} diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdViewController.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdViewController.swift index f4e1c41..d859d5e 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdViewController.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdViewController.swift @@ -7,43 +7,17 @@ import YandexMobileAds -final class AppOpenAdController: UIViewController { - private var appOpenAd: YMAAppOpenAd? - private lazy var interstitialAdLoader: YMAAppOpenAdLoader = { - let loader = YMAAppOpenAdLoader() - loader.delegate = self - return loader - }() - - private lazy var showButton: UIButton = { - let button = UIButton( - configuration: .tinted(), - primaryAction: UIAction(title: "Show ad") { [weak self] _ in - guard let self else { return } - self.appOpenAd?.show(from: self) - self.showButton.isEnabled = false - self.statusLabel.text = "Ad is ready for presentation. Leave the application, then return to see the ad." - } - ) - button.translatesAutoresizingMaskIntoConstraints = false - button.setTitle("Show ad", for: .normal) - button.isEnabled = false - return button - }() - +final class AppOpenAdViewController: UIViewController { private lazy var loadButton: UIButton = { let button = UIButton( configuration: .tinted(), - primaryAction: UIAction(title: "Load ad") { [weak self] _ in + primaryAction: UIAction(title: "Load Ad") { [weak self] _ in guard let self else { return } - - // Replace demo-appopenad-direct with actual Ad Unit ID - let configuration = YMAAdRequestConfiguration(adUnitID: "demo-appopenad-direct") - self.appOpenAdLoader.loadAd(with: configuration) + AppOpenAdController.shared.loadAd() } ) button.translatesAutoresizingMaskIntoConstraints = false - button.setTitle("Load ad", for: .normal) + button.setTitle("Load Ad", for: .normal) return button }() @@ -56,86 +30,54 @@ final class AppOpenAdController: UIViewController { return label }() - private var messageDescription: String { - "AppOpenAd with Unit ID: \(String(describing: appOpenAd?.adInfo?.adUnitId))" - } - override func viewDidLoad() { super.viewDidLoad() setupUI() addSubviews() setupConstraints() + AppOpenAdController.shared.delegate = self } // MARK: - UI private func setupUI() { view.backgroundColor = .white - title = "AppOpenAd" + title = "App Open Ad" } private func addSubviews() { view.addSubview(loadButton) - view.addSubview(showButton) view.addSubview(statusLabel) } private func setupConstraints() { NSLayoutConstraint.activate([ loadButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 100), - loadButton.trailingAnchor.constraint(equalTo: view.centerXAnchor, constant: -20), + loadButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), - showButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 100), - showButton.leadingAnchor.constraint(equalTo: view.centerXAnchor, constant: 20), - - statusLabel.topAnchor.constraint(equalTo: showButton.bottomAnchor, constant: 50), + statusLabel.topAnchor.constraint(equalTo: loadButton.bottomAnchor, constant: 50), statusLabel.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16), statusLabel.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16) ]) } } -// MARK: - YMAAppOpenAdLoaderDelegate +// MARK: - AppOpenAdControllerDelegate -extension AppOpenAdController: YMAAppOpenAdLoaderDelegate { - func appOpenAdLoader(_ adLoader: YMAAppOpenAdLoader, didLoad appOpenAd: YMAAppOpenAd) { - self.appOpenAd = appOpenAd - self.appOpenAd.delegate = self - showButton.isEnabled = true - statusLabel.text = "Ad is loaded." - print("\(messageDescription) loaded") +extension AppOpenAdViewController: AppOpenAdControllerDelegate { + func appOpenAdControllerDidLoad(_ appOpenAdController: AppOpenAdController) { + statusLabel.text = "Ad is ready for presentation. Leave the application, then return to see the ad." } - func appOpenAdLoader(_ adLoader: YMAAppOpenAdLoader, didFailToLoadWithError error: YMAAdRequestError) { - let id = error.adUnitId - let error = error.error - statusLabel.text = "Ad failed to load." - print("Loading failed for Ad with Unit ID: \(String(describing: id)). Error: \(String(describing: error))") - } -} - -// MARK: - YMAAppOpenAdDelegate - -extension AppOpenAdController: YMAAppOpenAdDelegate { - func appOpenAd(_ appOpenAd: YMAAppOpenAd, didFailToShowWithError error: Error) { - statusLabel.text = "Ad failed to show." - print("\(messageDescription) failed to show. Error: \(error)") - } - - func appOpenAdDidShow(_ appOpenAd: YMAAppOpenAd) { - print("\(messageDescription) did show") - } - - func appOpenAdDidDismiss(_ appOpenAd: YMAAppOpenAd) { + func appOpenAdControllerDidDismiss(_ appOpenAdController: AppOpenAdController) { statusLabel.text = "Ad is not loaded." - print("\(messageDescription) did dismiss") } - func appOpenAdDidClick(_ appOpenAd: YMAAppOpenAd) { - print("\(messageDescription) did click") + func appOpenAdController(_ appOpenAdController: AppOpenAdController, didFailToLoadWithError error: Error) { + statusLabel.text = "Ad failed to load." } - func appOpenAd(_ appOpenAd: YMAAppOpenAd, didTrackImpressionWithData impressionData: YMAImpressionData?) { - print("\(messageDescription) did track impression") + func appOpenAdController(_ appOpenAdController: AppOpenAdController, didFailToShowWithError error: Error) { + statusLabel.text = "Ad failed to show." } } diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Interstitial/InterstitialAdViewController.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Interstitial/InterstitialAdViewController.swift index 28ffda9..b11e429 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Interstitial/InterstitialAdViewController.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Interstitial/InterstitialAdViewController.swift @@ -46,10 +46,6 @@ final class InterstitialAdViewController: UIViewController { return button }() - private var messageDescription: String { - "Interstitial Ad with Unit ID: \(String(describing: interstitialAd?.adInfo?.adUnitId))" - } - override func viewDidLoad() { super.viewDidLoad() setupUI() @@ -78,6 +74,10 @@ final class InterstitialAdViewController: UIViewController { presentButton.leadingAnchor.constraint(equalTo: view.centerXAnchor, constant: 20) ]) } + + private func makeMessageDescription(_ interstitialAd: YMAInterstitialAd) -> String { + "Interstitial Ad with Unit ID: \(String(describing: interstitialAd.adInfo?.adUnitId))" + } } // MARK: - YMAInterstitialAdLoaderDelegate @@ -85,9 +85,9 @@ final class InterstitialAdViewController: UIViewController { extension InterstitialAdViewController: YMAInterstitialAdLoaderDelegate { func interstitialAdLoader(_ adLoader: YMAInterstitialAdLoader, didLoad interstitialAd: YMAInterstitialAd) { self.interstitialAd = interstitialAd - self.interstitialAd.delegate = self + self.interstitialAd?.delegate = self presentButton.isEnabled = true - print("\(messageDescription) loaded") + print("\(makeMessageDescription(interstitialAd)) loaded") } func interstitialAdLoader(_ adLoader: YMAInterstitialAdLoader, didFailToLoadWithError error: YMAAdRequestError) { @@ -101,22 +101,22 @@ extension InterstitialAdViewController: YMAInterstitialAdLoaderDelegate { extension InterstitialAdViewController: YMAInterstitialAdDelegate { func interstitialAd(_ interstitialAd: YMAInterstitialAd, didFailToShowWithError error: Error) { - print("\(messageDescription) failed to show. Error: \(error)") + print("\(makeMessageDescription(interstitialAd)) failed to show. Error: \(error)") } func interstitialAdDidShow(_ interstitialAd: YMAInterstitialAd) { - print("\(messageDescription) did show") + print("\(makeMessageDescription(interstitialAd)) did show") } func interstitialAdDidDismiss(_ interstitialAd: YMAInterstitialAd) { - print("\(messageDescription) did dismiss") + print("\(makeMessageDescription(interstitialAd)) did dismiss") } func interstitialAdDidClick(_ interstitialAd: YMAInterstitialAd) { - print("\(messageDescription) did click") + print("\(makeMessageDescription(interstitialAd)) did click") } func interstitialAd(_ interstitialAd: YMAInterstitialAd, didTrackImpressionWith impressionData: YMAImpressionData?) { - print("\(messageDescription) did track impression") + print("\(makeMessageDescription(interstitialAd)) did track impression") } } diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Rewarded/RewardedAdViewController.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Rewarded/RewardedAdViewController.swift index 99127a4..1217b5c 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Rewarded/RewardedAdViewController.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Rewarded/RewardedAdViewController.swift @@ -47,10 +47,6 @@ final class RewardedAdViewController: UIViewController { return button }() - private var messageDescription: String { - "Rewarded Ad with Unit ID: \(String(describing: rewardedAd?.adInfo?.adUnitId))" - } - override func viewDidLoad() { super.viewDidLoad() setupUI() @@ -79,6 +75,10 @@ final class RewardedAdViewController: UIViewController { presentButton.leadingAnchor.constraint(equalTo: view.centerXAnchor, constant: 20) ]) } + + private func makeMessageDescription(_ rewardedAd: YMARewardedAd) -> String { + "Rewarded Ad with Unit ID: \(String(describing: rewardedAd.adInfo?.adUnitId))" + } } // MARK: - YMARewardedAdLoaderDelegate @@ -86,9 +86,9 @@ final class RewardedAdViewController: UIViewController { extension RewardedAdViewController: YMARewardedAdLoaderDelegate { func rewardedAdLoader(_ adLoader: YMARewardedAdLoader, didLoad rewardedAd: YMARewardedAd) { self.rewardedAd = rewardedAd - self.rewardedAd.delegate = self + self.rewardedAd?.delegate = self presentButton.isEnabled = true - print("\(messageDescription)) loaded") + print("\(makeMessageDescription(rewardedAd))) loaded") } func rewardedAdLoader(_ adLoader: YMARewardedAdLoader, didFailToLoadWithError error: YMAAdRequestError) { @@ -102,7 +102,7 @@ extension RewardedAdViewController: YMARewardedAdLoaderDelegate { extension RewardedAdViewController: YMARewardedAdDelegate { func rewardedAd(_ rewardedAd: YMARewardedAd, didReward reward: YMAReward) { - let message = "\(messageDescription) did reward: \(reward.amount) \(reward.type)" + let message = "\(makeMessageDescription(rewardedAd)) did reward: \(reward.amount) \(reward.type)" let alertController = UIAlertController(title: "Reward", message: message, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.cancel, handler: nil)) presentedViewController?.present(alertController, animated: true, completion: nil) @@ -110,22 +110,22 @@ extension RewardedAdViewController: YMARewardedAdDelegate { } func rewardedAd(_ rewardedAd: YMARewardedAd, didFailToShowWithError error: Error) { - print("\(messageDescription) failed to show. Error: \(error)") + print("\(makeMessageDescription(rewardedAd)) failed to show. Error: \(error)") } func rewardedAdDidShow(_ rewardedAd: YMARewardedAd) { - print("\(messageDescription) did show") + print("\(makeMessageDescription(rewardedAd)) did show") } func rewardedAdDidDismiss(_ rewardedAd: YMARewardedAd) { - print("\(messageDescription) did dismiss") + print("\(makeMessageDescription(rewardedAd)) did dismiss") } func rewardedAdDidClick(_ rewardedAd: YMARewardedAd) { - print("\(messageDescription) did click") + print("\(makeMessageDescription(rewardedAd)) did click") } func rewardedAd(_ rewardedAd: YMARewardedAd, didTrackImpressionWith impressionData: YMAImpressionData?) { - print("\(messageDescription) did track impression") + print("\(makeMessageDescription(rewardedAd)) did track impression") } } diff --git a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/YandexAdsViewController.swift b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/YandexAdsViewController.swift index d1b4401..ab0729a 100644 --- a/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/YandexAdsViewController.swift +++ b/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/YandexAdsViewController.swift @@ -27,7 +27,7 @@ enum YandexAdsCellModel: NavigationScreenDataSource, CaseIterable { case .rewarded: return RewardedAdViewController() case .appOpenAd: - return AppOpenAdController() + return AppOpenAdViewController() case .native: return NativeViewController() case .instream: diff --git a/changelog/mobileads/CHANGELOG.md b/changelog/mobileads/CHANGELOG.md index 2289446..00aa342 100644 --- a/changelog/mobileads/CHANGELOG.md +++ b/changelog/mobileads/CHANGELOG.md @@ -5,14 +5,17 @@ All notable changes to this project will be documented in this file. ### Added * App Open Ad format -* Improvements and optimizations +* New ad formats in rewarded +* Ability to close rewarded ad before reward * Updated minimum supported version to iOS 13 +* Improvements and optimizations ### Breaking changes * New banner ad size API * Interstitial ad loading and ad show API decomposition * Rewarded ad loading and ad show API decomposition * Removed deprecated methods `setAnalyticsReportingEnabled:(BOOL)enabled` and `flexibleSizeWithCGSize:(CGSize)size` +* See [migration guide](https://yandex.ru/support2/mobile-ads/ru/dev/ios/release/6-0-0-migration) # Version 5.9.1