Skip to content

Commit

Permalink
added support for adfox slider ad (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile-ads-github authored Jul 23, 2024
1 parent c599d5f commit df04562
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
0D62C42B2C4F8F370014CA12 /* NativeSliderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D62C42A2C4F8F370014CA12 /* NativeSliderView.swift */; };
0D62C42D2C4F8F470014CA12 /* AdFoxSliderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D62C42C2C4F8F470014CA12 /* AdFoxSliderViewController.swift */; };
14033F5E27201B8A00A24D5E /* MobileMediationInterstitialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14033F5D27201B8A00A24D5E /* MobileMediationInterstitialViewController.swift */; };
14033F6527201E2700A24D5E /* MobileMediationNativeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14033F6427201E2700A24D5E /* MobileMediationNativeViewController.swift */; };
14033F6827201F7900A24D5E /* MobileMediationRewardedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14033F6727201F7900A24D5E /* MobileMediationRewardedViewController.swift */; };
Expand Down Expand Up @@ -198,6 +200,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0D62C42A2C4F8F370014CA12 /* NativeSliderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativeSliderView.swift; sourceTree = "<group>"; };
0D62C42C2C4F8F470014CA12 /* AdFoxSliderViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdFoxSliderViewController.swift; sourceTree = "<group>"; };
14033F5D27201B8A00A24D5E /* MobileMediationInterstitialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileMediationInterstitialViewController.swift; sourceTree = "<group>"; };
14033F6427201E2700A24D5E /* MobileMediationNativeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileMediationNativeViewController.swift; sourceTree = "<group>"; };
14033F6727201F7900A24D5E /* MobileMediationRewardedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileMediationRewardedViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -357,6 +361,7 @@
14033F6127201D9E00A24D5E /* Native */ = {
isa = PBXGroup;
children = (
0D62C42A2C4F8F370014CA12 /* NativeSliderView.swift */,
147B0BCB27200D12005F4062 /* StarRatingView.swift */,
147B0BCD27200D14005F4062 /* NativeAdView.swift */,
147B0BCC27200D13005F4062 /* NativeAdView.xib */,
Expand Down Expand Up @@ -615,6 +620,7 @@
149931802722BD01005D2E87 /* Adfox */ = {
isa = PBXGroup;
children = (
0D62C42C2C4F8F470014CA12 /* AdFoxSliderViewController.swift */,
149931872722C423005D2E87 /* AdFoxBannerViewController.swift */,
1499318A2722CD44005D2E87 /* AdFoxInterstitialViewController.swift */,
149931832722BD94005D2E87 /* AdFoxNativeViewController.swift */,
Expand Down Expand Up @@ -1004,9 +1010,11 @@
14033F6827201F7900A24D5E /* MobileMediationRewardedViewController.swift in Sources */,
B394AC8627A868DB00D92CD9 /* AdPlayerErrorConverter.swift in Sources */,
14033FB92720457800A24D5E /* ContentPlayerControlsDelegate.swift in Sources */,
0D62C42B2C4F8F370014CA12 /* NativeSliderView.swift in Sources */,
4A8FA13B2BFB558700A3DB07 /* NativeBulkViewController.swift in Sources */,
14033FC02720457800A24D5E /* InstreamAdBreakPositionFormatter.swift in Sources */,
14033FBF2720457800A24D5E /* InstreamParametersParser.swift in Sources */,
0D62C42D2C4F8F470014CA12 /* AdFoxSliderViewController.swift in Sources */,
DEC81ADC2A53B9E7008FE935 /* String+Extensions.swift in Sources */,
14033F8527202B8D00A24D5E /* AdMobNativeAdView.swift in Sources */,
14033FBB2720457800A24D5E /* VideoAVPlayerDelegate.swift in Sources */,
Expand Down
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)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="4mM-ek-Fjh">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="4mM-ek-Fjh">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -878,6 +878,30 @@
<segue destination="4Xa-TD-ZUo" kind="show" id="Qhr-bE-DfX"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="7AC-Jw-nEu">
<rect key="frame" x="0.0" y="180.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="7AC-Jw-nEu" id="Rgx-4e-pDh">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Carousel" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eXB-1u-SC6">
<rect key="frame" x="8" y="11.5" width="398" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="eXB-1u-SC6" firstAttribute="leading" secondItem="Rgx-4e-pDh" secondAttribute="leading" constant="8" id="Wpj-Bd-6Ov"/>
<constraint firstAttribute="trailing" secondItem="eXB-1u-SC6" secondAttribute="trailing" constant="8" id="agi-8d-0IP"/>
<constraint firstItem="eXB-1u-SC6" firstAttribute="centerY" secondItem="Rgx-4e-pDh" secondAttribute="centerY" id="fUZ-QN-5Gi"/>
</constraints>
</tableViewCellContentView>
<connections>
<segue destination="fKx-YV-AmC" kind="show" id="Ilp-1B-pkR"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand Down Expand Up @@ -1135,7 +1159,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="HEe-rf-z2Q" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="7293" y="4428"/>
<point key="canvasLocation" x="8154" y="4387"/>
</scene>
<!--AdFox banner-->
<scene sceneID="tlH-Cs-uBI">
Expand Down Expand Up @@ -1544,6 +1568,22 @@
</objects>
<point key="canvasLocation" x="10119" y="-5456"/>
</scene>
<!--Ad Fox Slider View Controller-->
<scene sceneID="Gay-hO-cSC">
<objects>
<viewController id="fKx-YV-AmC" customClass="AdFoxSliderViewController" customModule="YandexMobileAdsExample" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="zpH-vz-kRc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="gm0-ic-wRS"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="oG3-Hk-weX"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CUl-rU-1xo" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="6718.840579710145" y="4372.7678571428569"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
Expand Down
Loading

0 comments on commit df04562

Please sign in to comment.