Skip to content

Commit 3746769

Browse files
Merge pull request #123 from teads/handle_resize_delegate
Use of didUpdateRatio delegate
2 parents f166313 + 167c0ca commit 3746769

File tree

6 files changed

+99
-13
lines changed

6 files changed

+99
-13
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ target 'TeadsDemoApp' do
88
use_frameworks!
99

1010
# Pods for TeadsDemoApp
11-
pod 'GoogleMobileAdsMediationTeads', '4.7.0'
11+
pod 'GoogleMobileAdsMediationTeads', '4.7.2'
1212

1313
end

TeadsDemoApp.xcodeproj/project.pbxproj

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
6AFAF671587558D46AE2EAC8 /* Pods_TeadsDemoApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B79512963E77F97E0E9430D /* Pods_TeadsDemoApp.framework */; };
1011
B501EC721F823541002909B9 /* WebViewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501EC711F823541002909B9 /* WebViewViewController.swift */; };
1112
B501EC791F823F6C002909B9 /* WebViewHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B501EC771F823BA8002909B9 /* WebViewHelper.swift */; };
1213
B501EC7C1F823F8A002909B9 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = B501EC6B1F8232B3002909B9 /* index.html */; };
@@ -40,6 +41,9 @@
4041
/* End PBXBuildFile section */
4142

4243
/* Begin PBXFileReference section */
44+
48B8DFE05488E339B96E8286 /* Pods-TeadsDemoApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TeadsDemoApp.release.xcconfig"; path = "Target Support Files/Pods-TeadsDemoApp/Pods-TeadsDemoApp.release.xcconfig"; sourceTree = "<group>"; };
45+
4B79512963E77F97E0E9430D /* Pods_TeadsDemoApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TeadsDemoApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
46+
91867719F32F3DB45575394B /* Pods-TeadsDemoApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TeadsDemoApp.debug.xcconfig"; path = "Target Support Files/Pods-TeadsDemoApp/Pods-TeadsDemoApp.debug.xcconfig"; sourceTree = "<group>"; };
4347
B501EC6A1F8232B3002909B9 /* ie10-viewport-bug-workaround.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "ie10-viewport-bug-workaround.js"; sourceTree = "<group>"; };
4448
B501EC6B1F8232B3002909B9 /* index.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
4549
B501EC6D1F8232B3002909B9 /* bootstrap-theme.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = "bootstrap-theme.css"; sourceTree = "<group>"; };
@@ -85,6 +89,7 @@
8589
isa = PBXFrameworksBuildPhase;
8690
buildActionMask = 2147483647;
8791
files = (
92+
6AFAF671587558D46AE2EAC8 /* Pods_TeadsDemoApp.framework in Frameworks */,
8893
);
8994
runOnlyForDeploymentPostprocessing = 0;
9095
};
@@ -95,13 +100,16 @@
95100
isa = PBXGroup;
96101
children = (
97102
B5660B78207FAEA700406869 /* TeadsSDK.framework */,
103+
4B79512963E77F97E0E9430D /* Pods_TeadsDemoApp.framework */,
98104
);
99105
name = Frameworks;
100106
sourceTree = "<group>";
101107
};
102108
9C4C2A8CC3AEB01218414AF6 /* Pods */ = {
103109
isa = PBXGroup;
104110
children = (
111+
91867719F32F3DB45575394B /* Pods-TeadsDemoApp.debug.xcconfig */,
112+
48B8DFE05488E339B96E8286 /* Pods-TeadsDemoApp.release.xcconfig */,
105113
);
106114
path = Pods;
107115
sourceTree = "<group>";
@@ -350,10 +358,12 @@
350358
isa = PBXNativeTarget;
351359
buildConfigurationList = B5555A441F7CDF80007406D4 /* Build configuration list for PBXNativeTarget "TeadsDemoApp" */;
352360
buildPhases = (
361+
4DE9DEBFE2E1DD64624F7CA5 /* [CP] Check Pods Manifest.lock */,
353362
B5555A2E1F7CDF80007406D4 /* Sources */,
354363
B5555A2F1F7CDF80007406D4 /* Frameworks */,
355364
B5555A301F7CDF80007406D4 /* Resources */,
356365
913FE1D31FEC291B003C6E5E /* ShellScript */,
366+
FBFB355C3083F93449930B2F /* [CP] Embed Pods Frameworks */,
357367
);
358368
buildRules = (
359369
);
@@ -415,6 +425,28 @@
415425
/* End PBXResourcesBuildPhase section */
416426

417427
/* Begin PBXShellScriptBuildPhase section */
428+
4DE9DEBFE2E1DD64624F7CA5 /* [CP] Check Pods Manifest.lock */ = {
429+
isa = PBXShellScriptBuildPhase;
430+
buildActionMask = 2147483647;
431+
files = (
432+
);
433+
inputFileListPaths = (
434+
);
435+
inputPaths = (
436+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
437+
"${PODS_ROOT}/Manifest.lock",
438+
);
439+
name = "[CP] Check Pods Manifest.lock";
440+
outputFileListPaths = (
441+
);
442+
outputPaths = (
443+
"$(DERIVED_FILE_DIR)/Pods-TeadsDemoApp-checkManifestLockResult.txt",
444+
);
445+
runOnlyForDeploymentPostprocessing = 0;
446+
shellPath = /bin/sh;
447+
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";
448+
showEnvVarsInLog = 0;
449+
};
418450
913FE1D31FEC291B003C6E5E /* ShellScript */ = {
419451
isa = PBXShellScriptBuildPhase;
420452
buildActionMask = 2147483647;
@@ -428,6 +460,32 @@
428460
shellPath = /bin/sh;
429461
shellScript = "echo \"Target architectures: $ARCHS\"\n\nAPP_PATH=\"${TARGET_BUILD_DIR}/${WRAPPER_NAME}\"\n\necho \"$APP_PATH\"\n\nfind \"$APP_PATH\" -name '*.framework' -type d | while read -r FRAMEWORK\ndo\nFRAMEWORK_EXECUTABLE_NAME=$(defaults read \"$FRAMEWORK/Info.plist\" CFBundleExecutable)\nFRAMEWORK_EXECUTABLE_PATH=\"$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME\"\necho \"Executable is $FRAMEWORK_EXECUTABLE_PATH\"\necho $(lipo -info \"$FRAMEWORK_EXECUTABLE_PATH\")\n\nFRAMEWORK_TMP_PATH=\"$FRAMEWORK_EXECUTABLE_PATH-tmp\"\n\n# remove simulator's archs if location is not simulator's directory\ncase \"${TARGET_BUILD_DIR}\" in\n*\"iphonesimulator\")\necho \"No need to remove archs\"\n;;\n*)\nif $(lipo \"$FRAMEWORK_EXECUTABLE_PATH\" -verify_arch \"i386\") ; then\nlipo -output \"$FRAMEWORK_TMP_PATH\" -remove \"i386\" \"$FRAMEWORK_EXECUTABLE_PATH\"\necho \"i386 architecture removed\"\nrm \"$FRAMEWORK_EXECUTABLE_PATH\"\nmv \"$FRAMEWORK_TMP_PATH\" \"$FRAMEWORK_EXECUTABLE_PATH\"\nfi\nif $(lipo \"$FRAMEWORK_EXECUTABLE_PATH\" -verify_arch \"x86_64\") ; then\nlipo -output \"$FRAMEWORK_TMP_PATH\" -remove \"x86_64\" \"$FRAMEWORK_EXECUTABLE_PATH\"\necho \"x86_64 architecture removed\"\nrm \"$FRAMEWORK_EXECUTABLE_PATH\"\nmv \"$FRAMEWORK_TMP_PATH\" \"$FRAMEWORK_EXECUTABLE_PATH\"\nfi\n;;\nesac\n\necho \"Completed for executable $FRAMEWORK_EXECUTABLE_PATH\"\necho $(lipo -info \"$FRAMEWORK_EXECUTABLE_PATH\")\n\ndone\n";
430462
};
463+
FBFB355C3083F93449930B2F /* [CP] Embed Pods Frameworks */ = {
464+
isa = PBXShellScriptBuildPhase;
465+
buildActionMask = 2147483647;
466+
files = (
467+
);
468+
inputPaths = (
469+
"${PODS_ROOT}/Target Support Files/Pods-TeadsDemoApp/Pods-TeadsDemoApp-frameworks.sh",
470+
"${PODS_ROOT}/GoogleMobileAdsMediationTeads/TeadsAdMobAdapter.framework",
471+
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
472+
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
473+
"${PODS_ROOT}/TeadsSDK/TeadsSDK.framework",
474+
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
475+
);
476+
name = "[CP] Embed Pods Frameworks";
477+
outputPaths = (
478+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TeadsAdMobAdapter.framework",
479+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
480+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
481+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TeadsSDK.framework",
482+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
483+
);
484+
runOnlyForDeploymentPostprocessing = 0;
485+
shellPath = /bin/sh;
486+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TeadsDemoApp/Pods-TeadsDemoApp-frameworks.sh\"\n";
487+
showEnvVarsInLog = 0;
488+
};
431489
/* End PBXShellScriptBuildPhase section */
432490

433491
/* Begin PBXSourcesBuildPhase section */
@@ -599,6 +657,7 @@
599657
};
600658
B5555A451F7CDF80007406D4 /* Debug */ = {
601659
isa = XCBuildConfiguration;
660+
baseConfigurationReference = 91867719F32F3DB45575394B /* Pods-TeadsDemoApp.debug.xcconfig */;
602661
buildSettings = {
603662
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
604663
CODE_SIGN_STYLE = Automatic;
@@ -620,6 +679,7 @@
620679
};
621680
B5555A461F7CDF80007406D4 /* Release */ = {
622681
isa = XCBuildConfiguration;
682+
baseConfigurationReference = 48B8DFE05488E339B96E8286 /* Pods-TeadsDemoApp.release.xcconfig */;
623683
buildSettings = {
624684
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
625685
CODE_SIGN_STYLE = Automatic;

TeadsDemoApp/Controllers/collectionViewController/CollectionViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ class CollectionViewController: UICollectionViewController, UICollectionViewDele
111111
}, completion: nil)
112112
}
113113

114+
public func didUpdateRatio(_ ad: TFAAdView, ratio: CGFloat) {
115+
adRatio = ratio
116+
self.collectionView?.performBatchUpdates({
117+
self.collectionView?.collectionViewLayout.invalidateLayout()
118+
}, completion: nil)
119+
}
120+
114121
func didFailToReceiveAd(_ ad: TFAAdView, adFailReason: AdFailReason) {
115122
self.shouldCloseAd = true
116123
self.collectionView?.performBatchUpdates({
@@ -125,6 +132,7 @@ class CollectionViewController: UICollectionViewController, UICollectionViewDele
125132
}, completion: nil)
126133
}
127134

135+
128136
public func adError(_ ad: TFAAdView, errorMessage: String) {
129137
}
130138
}

TeadsDemoApp/Controllers/scrollViewController/ScrollViewController.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,46 @@ class ScrollViewController: UIViewController, TFAAdDelegate {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
self.teadsAdView.delegate = self
20+
teadsAdView.delegate = self
2121
// the PID has been set in the storyboard
22-
self.teadsAdView.pid = UserDefaults.standard.integer(forKey: "PID")
22+
teadsAdView.pid = UserDefaults.standard.integer(forKey: "PID")
2323

2424
let teadsAdSettings = TeadsAdSettings(build: { (settings) in
2525
settings.enableDebug()
2626
})
27-
self.teadsAdView.setAdContainerView(container: self.teadsAdView)
28-
self.teadsAdView.load(teadsAdSettings: teadsAdSettings)
27+
28+
teadsAdView.load(teadsAdSettings: teadsAdSettings)
2929

3030
// We use an observer to know when a rotation happened, to resize the ad
3131
// You can use whatever way you want to do so
32-
NotificationCenter.default.addObserver(self, selector: #selector(self.rotationDetected), name: UIDevice.orientationDidChangeNotification, object: nil)
32+
NotificationCenter.default.addObserver(self, selector: #selector(rotationDetected), name: UIDevice.orientationDidChangeNotification, object: nil)
3333
}
3434

3535
deinit {
3636
NotificationCenter.default.removeObserver(self)
3737
}
3838

3939
@objc func rotationDetected() {
40-
if self.adRatio != nil {
41-
self.resizeTeadsAd(adRatio: self.adRatio!)
40+
if adRatio != nil {
41+
resizeTeadsAd(adRatio: adRatio!)
4242
}
4343
}
4444

4545
func resizeTeadsAd(adRatio: CGFloat) {
46-
let adHeight = self.view.frame.width/adRatio
47-
self.teadsAdHeightConstraint.constant = adHeight
46+
let adHeight = view.frame.width/adRatio
47+
teadsAdHeightConstraint.constant = adHeight
4848
}
4949

5050
// MARK: TFAAdDelegate
5151

5252
func didReceiveAd(_ ad: TFAAdView, adRatio: CGFloat) {
5353
self.adRatio = adRatio
54-
self.resizeTeadsAd(adRatio: adRatio)
54+
resizeTeadsAd(adRatio: adRatio)
5555
}
5656

5757
func didFailToReceiveAd(_ ad: TFAAdView, adFailReason: AdFailReason) {
58-
self.adRatio = 0
59-
self.teadsAdHeightConstraint.constant = 0
58+
adRatio = 0
59+
teadsAdHeightConstraint.constant = 0
6060
}
6161

6262
func adClose(_ ad: TFAAdView, userAction: Bool) {
@@ -69,4 +69,9 @@ class ScrollViewController: UIViewController, TFAAdDelegate {
6969
//be careful if you want to load another ad in the same page don't remove the observer
7070
NotificationCenter.default.removeObserver(self)
7171
}
72+
73+
public func didUpdateRatio(_ ad: TFAAdView, ratio: CGFloat) {
74+
adRatio = ratio
75+
resizeTeadsAd(adRatio: ratio)
76+
}
7277
}

TeadsDemoApp/Controllers/tableViewController/TableViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ class TableViewController: UITableViewController, TFAAdDelegate {
121121
NotificationCenter.default.removeObserver(self)
122122
}
123123

124+
public func didUpdateRatio(_ ad: TFAAdView, ratio: CGFloat) {
125+
adRatio = ratio
126+
//update slot with the right ratio
127+
resizeTeadsAd(adRatio: ratio)
128+
}
129+
124130
public func adError(_ ad: TFAAdView, errorMessage: String) {
125131
//be careful if you want to load another ad in the same page don't remove the observer
126132
NotificationCenter.default.removeObserver(self)

TeadsDemoApp/Controllers/webViewController/webViewHelper/SyncWebViewTFInReadAdView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class SyncWebViewTFInReadAdView: NSObject, WebViewHelperDelegate, TFAAdDe
108108

109109
}
110110

111+
111112
public func adClose(_ ad: TFAAdView, userAction: Bool) {
112113
//close the slot
113114
self.webViewHelper.closeSlot()
@@ -128,6 +129,12 @@ public class SyncWebViewTFInReadAdView: NSObject, WebViewHelperDelegate, TFAAdDe
128129
NotificationCenter.default.removeObserver(self)
129130
}
130131

132+
public func didUpdateRatio(_ ad: TFAAdView, ratio: CGFloat) {
133+
self.adRatio = ratio
134+
//update slot with the right ratio
135+
self.webViewHelper.updateSlot(adRatio: ratio)
136+
}
137+
131138
public func adDidCloseFullscreen(_ ad: TFAAdView) {
132139
//update the slot in case there was a rotation or a layout change to be sure that the ad has the right layout
133140
self.webViewHelper.updateSlot(adRatio: self.adRatio)

0 commit comments

Comments
 (0)