-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a79909a
commit b7e8ec1
Showing
10 changed files
with
199 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
Examples/YandexMobileAdsExample/YandexMobileAdsExample/AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...obileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdControllerDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Oops, something went wrong.