Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKOverlay list of options for testing #112

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Application/Sources/Test/TestRenderAdViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import NimbusKit

final class TestRenderAdViewController: UIViewController {
private let adMarkup: String
private let iTunesAppId: String?

private lazy var adContainerView: CustomAdContainerView = {
return CustomAdContainerView(ad: Self.getAdFromMarkup(adMarkup: adMarkup), viewController: self)
}()

init(adMarkup: String) {
init(adMarkup: String, iTunesAppId: String?) {
self.adMarkup = adMarkup
self.iTunesAppId = iTunesAppId

super.init(nibName: nil, bundle: nil)
}
Expand All @@ -25,9 +27,10 @@ final class TestRenderAdViewController: UIViewController {
fatalError("init(coder:) has not been implemented")
}

static func showBlocking(from: UIViewController, adMarkup: String) {
let adView = NimbusAdView(adPresentingViewController: nil)
let controller = NimbusAdViewController(adView: adView, ad: getAdFromMarkup(adMarkup: adMarkup), companionAd: nil)
static func showBlocking(from: UIViewController, adMarkup: String, iTunesAppId: String? = nil) {
let adView = NimbusAdView(adPresentingViewController: from)
adView.showsSKOverlay = iTunesAppId != nil
let controller = NimbusAdViewController(adView: adView, ad: getAdFromMarkup(adMarkup: adMarkup, iTunesAppId: iTunesAppId), companionAd: nil)
controller.modalPresentationStyle = .fullScreen

adView.adPresentingViewController = controller
Expand Down Expand Up @@ -60,9 +63,9 @@ final class TestRenderAdViewController: UIViewController {
}
}

static private func getAdFromMarkup(adMarkup: String) -> NimbusAd {
static private func getAdFromMarkup(adMarkup: String, iTunesAppId: String? = nil) -> NimbusAd {
let type: NimbusAuctionType = isVideoMarkup(adMarkup: adMarkup) ? .video : .static
return createNimbusAd(auctionType: type, markup: adMarkup)
return createNimbusAd(auctionType: type, markup: adMarkup, iTunesAppId: iTunesAppId)
}

static private func isVideoMarkup(adMarkup: String) -> Bool {
Expand All @@ -75,11 +78,15 @@ final class TestRenderAdViewController: UIViewController {
auctionType: NimbusAuctionType,
markup: String,
isMraid: Bool = true,
isInterstitial: Bool = true
isInterstitial: Bool = true,
iTunesAppId: String? = nil
) -> NimbusAd {
let adDimensions = isInterstitial ?
NimbusAdDimensions(width: 320, height: 480) :
NimbusAdDimensions(width: 300, height: 50)

let ext = NimbusAdExtensions(skAdNetwork: NimbusAdSkAdNetwork(advertisedAppStoreItemID: iTunesAppId))

return NimbusAd(
position: "",
auctionType: auctionType,
Expand All @@ -95,7 +102,7 @@ final class TestRenderAdViewController: UIViewController {
adDimensions: adDimensions,
trackers: nil,
isMraid: isMraid,
extensions: nil
extensions: iTunesAppId != nil ? ext : nil
)
}
}
49 changes: 46 additions & 3 deletions Application/Sources/Test/TestRenderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ class TestRenderViewController: DemoViewController {

var isBlocking = false

private var iTunesAppId: String?

private lazy var skoverlayMenuButton: UIButton = {
let closure: (UIAction) -> () = { [weak self] (action: UIAction) in
self?.iTunesAppId = switch action.identifier.rawValue {
case "timehop": "569077959"
case "yelp": "284910350"
case "ig": "389801252"
case "tinder": "547702041"
case "imgur": "639881495"
default: nil
}
}

let button = UIButton(type: .system)
button.menu = UIMenu(title: "", children: [
UIAction(title: "SKOverlay: None", identifier: .init("none"), handler: closure),
UIAction(title: "SKOverlay: Timehop", identifier: .init("timehop"), handler: closure),
UIAction(title: "SKOverlay: Yelp", identifier: .init("yelp"), handler: closure),
UIAction(title: "SKOverlay: Instagram", identifier: .init("ig"), handler: closure),
UIAction(title: "SKOverlay: Tinder", identifier: .init("tinder"), handler: closure),
UIAction(title: "SKOverlay: Imgur", identifier: .init("imgur"), handler: closure),
])

button.showsMenuAsPrimaryAction = true
button.changesSelectionAsPrimaryAction = true

return button
}()

private lazy var markupTextView: UITextView = {
let textView = UITextView()
textView.textColor = .turquoise
Expand Down Expand Up @@ -81,16 +111,29 @@ class TestRenderViewController: DemoViewController {
NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillShowNotification, object: nil)

setupSKOverlayPopup()
setupTextView()
setupTestButton()
}

private func setupSKOverlayPopup() {
view.addSubview(skoverlayMenuButton)

skoverlayMenuButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
skoverlayMenuButton.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: 16),
skoverlayMenuButton.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
skoverlayMenuButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16),
skoverlayMenuButton.heightAnchor.constraint(equalToConstant: 40)
])
}

private func setupTextView() {
view.addSubview(markupTextView)

markupTextView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
markupTextView.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: 16),
markupTextView.topAnchor.constraint(equalTo: skoverlayMenuButton.bottomAnchor, constant: 16),
markupTextView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
markupTextView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16)
])
Expand Down Expand Up @@ -128,10 +171,10 @@ class TestRenderViewController: DemoViewController {
markupTextView.resignFirstResponder()

if isBlocking {
TestRenderAdViewController.showBlocking(from: self, adMarkup: adMarkup)
TestRenderAdViewController.showBlocking(from: self, adMarkup: adMarkup, iTunesAppId: iTunesAppId)
} else {
navigationController?.pushViewController(
TestRenderAdViewController(adMarkup: adMarkup),
TestRenderAdViewController(adMarkup: adMarkup, iTunesAppId: iTunesAppId),
animated: true
)
}
Expand Down
Loading