-
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.
added support for adfox slider ad (#237)
- Loading branch information
1 parent
c599d5f
commit df04562
Showing
4 changed files
with
390 additions
and
3 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
92 changes: 92 additions & 0 deletions
92
Examples/YandexMobileAdsExample/YandexMobileAdsExample/Adfox/AdFoxSliderViewController.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,92 @@ | ||
/* | ||
* Version for iOS © 2015–2021 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 YandexMobileAds | ||
|
||
class AdFoxSliderViewController: UIViewController { | ||
private let loadButton: UIButton = { | ||
let button = UIButton(type: .system) | ||
button.translatesAutoresizingMaskIntoConstraints = false | ||
button.setTitle("Load", for: .normal) | ||
return button | ||
}() | ||
|
||
private let stateLabel: UILabel = { | ||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
return label | ||
}() | ||
|
||
private var adLoader: NativeAdLoader! | ||
private let sliderAdView: NativeSliderView = { | ||
let view = NativeSliderView(frame: .zero) | ||
view.translatesAutoresizingMaskIntoConstraints = false | ||
view.isHidden = true | ||
view.autoscrollInterval = 5 | ||
view.isAutoscrollEnabled = true | ||
return view | ||
}() | ||
|
||
private var ad: NativeAd? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
adLoader = NativeAdLoader() | ||
adLoader.delegate = self | ||
loadButton.addTarget(self, action: #selector(loadSliderAd), for: .primaryActionTriggered) | ||
layoutAdView() | ||
} | ||
|
||
@objc private func loadSliderAd() { | ||
var parameters = Dictionary<String, String>() | ||
parameters["adf_ownerid"] = "270901" | ||
parameters["adf_p1"] = "ddfla" | ||
parameters["adf_p2"] = "fksh" | ||
let requestConfiguration = MutableNativeAdRequestConfiguration(adUnitID: "R-M-243655-10") | ||
requestConfiguration.parameters = parameters | ||
adLoader.loadAd(with: requestConfiguration) | ||
} | ||
|
||
private func layoutAdView() { | ||
view.addSubview(loadButton) | ||
view.addSubview(stateLabel) | ||
NSLayoutConstraint.activate([ | ||
loadButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16), | ||
loadButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), | ||
loadButton.widthAnchor.constraint(equalToConstant: 50), | ||
stateLabel.leadingAnchor.constraint(equalTo: loadButton.leadingAnchor), | ||
stateLabel.topAnchor.constraint(equalTo: loadButton.bottomAnchor, constant: 10), | ||
stateLabel.widthAnchor.constraint(equalToConstant: 100), | ||
stateLabel.heightAnchor.constraint(equalToConstant: 30) | ||
]) | ||
view.addSubview(sliderAdView) | ||
NSLayoutConstraint.activate([ | ||
sliderAdView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10), | ||
sliderAdView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10), | ||
sliderAdView.topAnchor.constraint(equalTo: stateLabel.bottomAnchor, constant: 8), | ||
sliderAdView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -10), | ||
]) | ||
} | ||
} | ||
|
||
extension AdFoxSliderViewController: NativeAdLoaderDelegate { | ||
func nativeAdLoader(_ loader: NativeAdLoader, didLoad ad: NativeAd) { | ||
self.ad = ad | ||
sliderAdView.isHidden = false | ||
do { | ||
try sliderAdView.bind(with: ad) | ||
stateLabel.text = StateUtils.loaded() | ||
} catch { | ||
stateLabel.text = StateUtils.loadError(error) | ||
} | ||
} | ||
|
||
func nativeAdLoader(_ loader: NativeAdLoader, didFailLoadingWithError error: any Error) { | ||
stateLabel.text = StateUtils.loadError(error) | ||
} | ||
} |
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
Oops, something went wrong.