Skip to content

Commit 5bd8a28

Browse files
committed
fix native CTA label -> button, add bind logic
1 parent 8d6132c commit 5bd8a28

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

MediationAdapters/TeadsAppLovinAdapter/TeadsMediationAdapter.swift

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import TeadsSDK
1212
@objc(TeadsMediationAdapter)
1313
final class TeadsMediationAdapter: ALMediationAdapter {
1414
var currentNativePlacement: TeadsNativeAdPlacement?
15+
weak var nativeAd: TeadsNativeAd?
1516
weak var nativeDelegate: MANativeAdAdapterDelegate?
1617

1718
var currentInReadPlacement: TeadsInReadAdPlacement?
1819
weak var bannerDelegate: MAAdViewAdapterDelegate?
19-
weak var currentAdView: TeadsInReadAdView?
20+
weak var inReadAdView: TeadsInReadAdView?
2021

2122
@objc override func initialize(with parameters: MAAdapterInitializationParameters, completionHandler: @escaping (MAAdapterInitializationStatus, String?) -> Void) {
2223
Teads.configure()
@@ -77,12 +78,12 @@ final class TeadsMediationAdapter: ALMediationAdapter {
7778
extension TeadsMediationAdapter: TeadsInReadAdPlacementDelegate {
7879
func didReceiveAd(ad: TeadsInReadAd, adRatio: TeadsAdRatio) {
7980
let adView = TeadsInReadAdView(bind: ad)
80-
currentAdView = adView
81+
inReadAdView = adView
8182
bannerDelegate?.didLoadAd(forAdView: adView)
8283
}
8384

8485
func didUpdateRatio(ad: TeadsInReadAd, adRatio: TeadsAdRatio) {
85-
currentAdView?.updateHeight(with: adRatio)
86+
inReadAdView?.updateHeight(with: adRatio)
8687
}
8788
}
8889

@@ -92,10 +93,10 @@ extension TeadsMediationAdapter: TeadsNativeAdPlacementDelegate {
9293
nativeDelegate?.didFailToLoadNativeAdWithError(.missingRequiredNativeAdAssets)
9394
return
9495
}
95-
96+
nativeAd = ad
9697
ad.delegate = self
9798

98-
let nativeAd = MANativeAd(format: .native) { builder in
99+
let nativeAd = AppLovinTeadsNativeAd(parent: self) { builder in
99100
if let title = ad.title?.text {
100101
builder.title = title
101102
}
@@ -111,6 +112,9 @@ extension TeadsMediationAdapter: TeadsNativeAdPlacementDelegate {
111112
ad.icon?.loadImage { icon in
112113
builder.icon = MANativeAdImage(image: icon)
113114
}
115+
if let adChoices = ad.adChoices {
116+
builder.optionsView = TeadsAdChoicesView(binding: adChoices)
117+
}
114118
}
115119

116120
nativeDelegate?.didLoadAd(for: nativeAd, withExtraInfo: nil)
@@ -157,3 +161,27 @@ extension TeadsMediationAdapter: TeadsAdDelegate {
157161
bannerDelegate?.didCollapseAdViewAd()
158162
}
159163
}
164+
165+
166+
final class AppLovinTeadsNativeAd: MANativeAd {
167+
weak var parentAdatper: TeadsMediationAdapter?
168+
169+
init(parent: TeadsMediationAdapter, builderBlock: MANativeAdBuilderBlock) {
170+
super.init(format: .native, builderBlock: builderBlock)
171+
self.parentAdatper = parent
172+
}
173+
174+
override func prepareView(forInteraction nativeAdView: MANativeAdView) {
175+
guard let nativeAd = parentAdatper?.nativeAd else {
176+
parentAdatper?.e("Failed to register native ad views: native ad is nil.", becauseOf: nil)
177+
return
178+
}
179+
nativeAd.register(containerView: nativeAdView)
180+
nativeAdView.titleLabel?.bind(component: nativeAd.title)
181+
nativeAdView.bodyLabel?.bind(component: nativeAd.content)
182+
nativeAdView.callToActionButton?.bind(component: nativeAd.callToAction)
183+
nativeAdView.iconImageView?.bind(component: nativeAd.icon)
184+
nativeAdView.mediaContentView?.bind(component: nativeAd.video ?? nativeAd.image)
185+
nativeAdView.advertiserLabel?.bind(component: nativeAd.adChoices)
186+
}
187+
}

TeadsSampleApp/Controllers/Native/AppLovin/TableView/AppLovinNativeAdView.xib

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AppLovinNativeAdView"/>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14-
<view contentMode="scaleToFill" id="Yr2-r6-oZu" customClass="AppLovinNativeAdView" customModule="TeadsSDKIntegrationTestsApp" customModuleProvider="target">
14+
<view contentMode="scaleToFill" id="Yr2-r6-oZu" customClass="AppLovinNativeAdView" customModule="TeadsSampleApp" customModuleProvider="target">
1515
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1616
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1717
<subviews>
@@ -25,7 +25,7 @@
2525
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="5q7-di-aL4">
2626
<rect key="frame" x="108" y="24" width="243" height="39.5"/>
2727
<subviews>
28-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Headline" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LAQ-A6-bjb">
28+
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Headline" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LAQ-A6-bjb">
2929
<rect key="frame" x="0.0" y="0.0" width="243" height="19.5"/>
3030
<fontDescription key="fontDescription" type="boldSystem" pointSize="16"/>
3131
<nil key="textColor"/>
@@ -69,37 +69,36 @@
6969
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
7070
<nil key="highlightedColor"/>
7171
</label>
72-
<label opaque="NO" userInteractionEnabled="NO" tag="7" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Install" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="L8C-PP-3Zt">
73-
<rect key="frame" x="308.5" y="375.5" width="42.5" height="19.5"/>
74-
<fontDescription key="fontDescription" type="system" pointSize="16"/>
75-
<nil key="textColor"/>
76-
<nil key="highlightedColor"/>
77-
</label>
7872
<view tag="6" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9dO-Pv-Qh0" userLabel="ContentView">
7973
<rect key="frame" x="24" y="100" width="327" height="200"/>
8074
<constraints>
8175
<constraint firstAttribute="height" constant="200" id="eHR-dH-zuo"/>
8276
</constraints>
8377
</view>
78+
<button opaque="NO" tag="7" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="naI-wO-42r" userLabel="CTA Button">
79+
<rect key="frame" x="288.5" y="375.5" width="62.5" height="31"/>
80+
<state key="normal" title="Button"/>
81+
<buttonConfiguration key="configuration" style="plain" title="Install"/>
82+
</button>
8483
</subviews>
8584
<viewLayoutGuide key="safeArea" id="MOU-oS-ZgE"/>
8685
<color key="backgroundColor" systemColor="systemGray6Color"/>
8786
<constraints>
87+
<constraint firstItem="MOU-oS-ZgE" firstAttribute="trailing" secondItem="naI-wO-42r" secondAttribute="trailing" constant="24" id="15R-1h-VGA"/>
8888
<constraint firstItem="q25-37-4MT" firstAttribute="top" secondItem="Yr2-r6-oZu" secondAttribute="top" id="31P-0d-5CA"/>
8989
<constraint firstItem="Ddf-dS-jO7" firstAttribute="top" secondItem="Yr2-r6-oZu" secondAttribute="top" constant="24" id="3TD-Fl-tUs"/>
90-
<constraint firstItem="L8C-PP-3Zt" firstAttribute="top" secondItem="IHI-TG-ptk" secondAttribute="bottom" constant="14" id="3sd-wb-3r4"/>
9190
<constraint firstItem="IHI-TG-ptk" firstAttribute="leading" secondItem="MOU-oS-ZgE" secondAttribute="leading" constant="20" id="4ua-S6-zNr"/>
9291
<constraint firstItem="MOU-oS-ZgE" firstAttribute="trailing" secondItem="9dO-Pv-Qh0" secondAttribute="trailing" constant="24" id="5Fe-4G-wJj"/>
9392
<constraint firstItem="5q7-di-aL4" firstAttribute="top" secondItem="Yr2-r6-oZu" secondAttribute="top" constant="24" id="BTo-HS-v8I"/>
9493
<constraint firstItem="MOU-oS-ZgE" firstAttribute="trailing" secondItem="IHI-TG-ptk" secondAttribute="trailing" constant="20" id="D3u-Tr-GH9"/>
9594
<constraint firstItem="9dO-Pv-Qh0" firstAttribute="leading" secondItem="MOU-oS-ZgE" secondAttribute="leading" constant="24" id="E66-HZ-xeL"/>
9695
<constraint firstItem="5q7-di-aL4" firstAttribute="leading" secondItem="Ddf-dS-jO7" secondAttribute="trailing" constant="24" id="FyT-2m-v00"/>
9796
<constraint firstItem="9dO-Pv-Qh0" firstAttribute="top" secondItem="Ddf-dS-jO7" secondAttribute="bottom" constant="16" id="Gu1-sh-iyp"/>
97+
<constraint firstItem="naI-wO-42r" firstAttribute="top" secondItem="IHI-TG-ptk" secondAttribute="bottom" constant="14" id="JTx-19-1ek"/>
9898
<constraint firstItem="Ddf-dS-jO7" firstAttribute="leading" secondItem="MOU-oS-ZgE" secondAttribute="leading" constant="24" id="nGo-Xv-oFc"/>
9999
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="q25-37-4MT" secondAttribute="trailing" constant="20" symbolic="YES" id="njk-1L-eYa"/>
100100
<constraint firstItem="q25-37-4MT" firstAttribute="leading" secondItem="Yr2-r6-oZu" secondAttribute="leading" id="o9P-mb-jkZ"/>
101101
<constraint firstItem="MOU-oS-ZgE" firstAttribute="trailing" secondItem="5q7-di-aL4" secondAttribute="trailing" constant="24" id="vaI-N9-hRD"/>
102-
<constraint firstItem="MOU-oS-ZgE" firstAttribute="trailing" secondItem="L8C-PP-3Zt" secondAttribute="trailing" constant="24" id="vm0-dP-p6s"/>
103102
<constraint firstItem="IHI-TG-ptk" firstAttribute="top" secondItem="9dO-Pv-Qh0" secondAttribute="bottom" constant="23" id="wZW-a0-Dgd"/>
104103
</constraints>
105104
<point key="canvasLocation" x="32.799999999999997" y="296.40179910044981"/>

TeadsSampleApp/Controllers/Native/AppLovin/TableView/NativeAppLovinTableViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extension NativeAppLovinTableViewController: MANativeAdDelegate {
124124
}
125125

126126
func didClickNativeAd(_ ad: MAAd) {
127+
print("didClickNativeAd")
127128
// did click on native ad
128129
}
129130
}

0 commit comments

Comments
 (0)