Skip to content

Commit

Permalink
Mintegral integration (#120)
Browse files Browse the repository at this point in the history
* add mintegral test cases

* add NimbusMintegralKit dependency. 

* Remove Package.resolved from repository
  • Loading branch information
standa-dev authored Nov 18, 2024
1 parent 59ed94c commit 0b251eb
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Pods/
# Swift Package Manager
.build/
Packages/
Package.resolved

# Secrets
secrets.json
Expand Down
59 changes: 0 additions & 59 deletions Application/Package.resolved

This file was deleted.

3 changes: 2 additions & 1 deletion Application/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ let package = Package(
.product(name: "NimbusVungleKit", package: "nimbus-ios-sdk"),
.product(name: "NimbusUnityKit", package: "nimbus-ios-sdk"),
.product(name: "NimbusMobileFuseKit", package: "nimbus-ios-sdk"),
.product(name: "NimbusAdMobKit", package: "nimbus-ios-sdk")
.product(name: "NimbusAdMobKit", package: "nimbus-ios-sdk"),
.product(name: "NimbusMintegralKit", package: "nimbus-ios-sdk"),
],
path: "Sources")
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Mintegral+Initialization.swift
// Nimbus
// Created on 10/30/24
// Copyright © 2024 Nimbus Advertising Solutions Inc. All rights reserved.
//

import UIKit
import NimbusKit
import MTGSDK
#if canImport(NimbusSDK) // CocoaPods
import NimbusSDK
#else // Swift Package Manager
import NimbusMintegralKit
#endif

fileprivate var mintegralAppId = Bundle.main.infoDictionary?["Mintegral App ID"] as! String
fileprivate var mintegralAppKey = Bundle.main.infoDictionary?["Mintegral App Key"] as! String

extension UIApplicationDelegate {
func setupMintegralDemand() {
/// It's important to call initialize as soon as the app launches
MTGSDK.sharedInstance().setAppID(mintegralAppId, apiKey: mintegralAppKey)
Nimbus.shared.renderers[.mintegral] = NimbusMintegralAdRenderer()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// MintegralBannerViewController.swift
// Nimbus
// Created on 10/30/24
// Copyright © 2024 Nimbus Advertising Solutions Inc. All rights reserved.
//

import UIKit
import NimbusKit
#if canImport(NimbusSDK) // CocoaPods
import NimbusSDK
#elseif canImport(NimbusMintegralKit) // Swift Package Manager
import NimbusMintegralKit
#endif

class MintegralBannerViewController: MintegralViewController {
var adController: AdController?
let adManager = NimbusAdManager()

override func viewDidLoad() {
super.viewDidLoad()

adManager.delegate = self
adManager.showAd(
request: .forBannerAd(position: "banner").withMintegral(adUnitId: "1541918", placementId: nil),
container: view,
refreshInterval: 30,
adPresentingViewController: self
)
}
}

extension MintegralBannerViewController: NimbusAdManagerDelegate {
func didRenderAd(request: NimbusRequest, ad: NimbusAd, controller: AdController) {
print("didRenderAd")
adController = controller
adController?.delegate = self
nimbusAd = ad
}

func didCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) {
print("didCompleteNimbusRequest")
}

func didFailNimbusRequest(request: NimbusRequest, error: NimbusError) {
print("didFailNimbusRequest: \(error.localizedDescription)")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// MintegralInterstitialViewController.swift
// Nimbus
// Created on 11/1/24
// Copyright © 2024 Nimbus Advertising Solutions Inc. All rights reserved.
//

import UIKit
import NimbusKit
#if canImport(NimbusSDK) // CocoaPods
import NimbusSDK
#elseif canImport(NimbusMintegralKit) // Swift Package Manager
import NimbusMintegralKit
#endif

class MintegralInterstitialViewController: MintegralViewController {
var adController: AdController?
let adManager = NimbusAdManager()

override func viewDidLoad() {
super.viewDidLoad()

adManager.delegate = self
adManager.showBlockingAd(
request: .forInterstitialAd(position: "interstitial").withMintegral(adUnitId: "1541952", placementId: nil),
closeButtonDelay: 0,
adPresentingViewController: self
)
}
}

extension MintegralInterstitialViewController: NimbusAdManagerDelegate {
func didRenderAd(request: NimbusRequest, ad: NimbusAd, controller: AdController) {
print("didRenderAd")
adController = controller
adController?.delegate = self
nimbusAd = ad
}

func didCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) {
print("didCompleteNimbusRequest")
}

func didFailNimbusRequest(request: NimbusRequest, error: NimbusError) {
print("didFailNimbusRequest: \(error.localizedDescription)")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// MintegralNativeViewController.swift
// Nimbus
// Created on 11/8/24
// Copyright © 2024 Nimbus Advertising Solutions Inc. All rights reserved.
//

import UIKit
import NimbusKit
import MTGSDK
#if canImport(NimbusSDK) // CocoaPods
import NimbusSDK
#elseif canImport(NimbusMintegralKit) // Swift Package Manager
import NimbusMintegralKit
#endif

class MintegralNativeViewController: MintegralViewController {
var adController: AdController?
let adManager = NimbusAdManager()

let contentView = UIView()

override func viewDidLoad() {
super.viewDidLoad()

if let renderer = Nimbus.shared.renderers[.mintegral] as? NimbusMintegralAdRenderer {
renderer.adRendererDelegate = self
}

contentView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(contentView)
NSLayoutConstraint.activate([
contentView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
contentView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
contentView.topAnchor.constraint(equalTo: headerView.bottomAnchor),
contentView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
])

adManager.delegate = self
adManager.showAd(
request: NimbusRequest.forNativeAd(position: "native").withMintegral(adUnitId: "1541926"),
container: contentView,
adPresentingViewController: self
)
}
}

extension MintegralNativeViewController: NimbusAdManagerDelegate {
func didRenderAd(request: NimbusRequest, ad: NimbusAd, controller: AdController) {
print("didRenderAd")
adController = controller
adController?.delegate = self
nimbusAd = ad
}

func didCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) {
print("didCompleteNimbusRequest")
}

func didFailNimbusRequest(request: NimbusRequest, error: NimbusError) {
print("didFailNimbusRequest: \(error.localizedDescription)")
}
}

extension MintegralNativeViewController: NimbusMintegralAdRendererDelegate {
func nativeAdViewForRendering(container: UIView, campaign: MTGCampaign) -> any NimbusMintegralNativeAdViewType {
MintegralNativeAdView(campaign: campaign)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MintegralRewardedViewController.swift
// Nimbus
// Created on 11/1/24
// Copyright © 2024 Nimbus Advertising Solutions Inc. All rights reserved.
//

import UIKit
import NimbusKit
#if canImport(NimbusSDK) // CocoaPods
import NimbusSDK
#elseif canImport(NimbusMintegralKit) // Swift Package Manager
import NimbusMintegralKit
#endif

class MintegralRewardedViewController: MintegralViewController {
var adController: AdController?
let adManager = NimbusAdManager()

override func viewDidLoad() {
super.viewDidLoad()

adManager.delegate = self
adManager.showRewardedAd(
request: .forRewardedVideo(position: "rewarded").withMintegral(adUnitId: "1541935"),
adPresentingViewController: self
)
}
}

extension MintegralRewardedViewController: NimbusAdManagerDelegate {
func didRenderAd(request: NimbusRequest, ad: NimbusAd, controller: AdController) {
print("didRenderAd")
adController = controller
adController?.delegate = self
nimbusAd = ad
}

func didCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) {
print("didCompleteNimbusRequest")
}

func didFailNimbusRequest(request: NimbusRequest, error: NimbusError) {
print("didFailNimbusRequest: \(error.localizedDescription)")
}
}
1 change: 1 addition & 0 deletions Application/Sources/Initialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
setupAmazonDemand()
setupUnityDemand()
setupVungleDemand()
setupMintegralDemand()

// Meta and LiveRamp requires att permissions to run properly
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) { [weak self] in
Expand Down
19 changes: 18 additions & 1 deletion Application/Sources/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ enum MainItem: String, NavigationItem {
Section(header: "APS", items: APSSample.allCases),
Section(header: "Meta Audience Network", items: MetaSample.allCases),
Section(header: "Unity", items: UnitySample.allCases),
Section(header: "Vungle", items: VungleSample.allCases)
Section(header: "Vungle", items: VungleSample.allCases),
Section(header: "Mintegral", items: Mintegral.allCases)
])
case .testRender:
return TestRenderViewController(
Expand Down Expand Up @@ -129,6 +130,22 @@ enum DynamicPriceNimbusRendering: String, NavigationItem {
}
}

enum Mintegral: String, NavigationItem {
case banner = "Banner"
case native = "Native"
case interstitial = "Interstitial"
case rewarded = "Rewarded Video"

func destinationController(parent: String) -> UIViewController {
return switch self {
case .banner: MintegralBannerViewController(headerTitle: "Mintegral Banner", headerSubTitle: "")
case .native: MintegralNativeViewController(headerTitle: "Mintegral Native", headerSubTitle: "")
case .interstitial: MintegralInterstitialViewController(headerTitle: "Mintegral Interstitial", headerSubTitle: "")
case .rewarded: MintegralRewardedViewController(headerTitle: "Mintegral Rewarded", headerSubTitle: "")
}
}
}

enum AdMob: String, NavigationItem {
case banner = "Banner"
case native = "Native Ad"
Expand Down
18 changes: 4 additions & 14 deletions Application/Sources/UI/AdMobViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@ import UIKit
import NimbusKit

/// When integrating AdMob, consider examples like AdMobBannerViewController inherit from UIViewController.
/// Both SampleAdViewController and AdMobViewController just facilitate the needs of the sample app.
class AdMobViewController: SampleAdViewController {
weak var sweepingInterceptor: SweepingInterceptor?

deinit {
NimbusAdManager.requestInterceptors?.removeAll(where: { $0 === sweepingInterceptor })
}

override func viewDidLoad() {
super.viewDidLoad()

let sweepingInterceptor = SweepingInterceptor(keep: .admob)
NimbusAdManager.requestInterceptors?.append(sweepingInterceptor)
self.sweepingInterceptor = sweepingInterceptor
/// Both DemandViewController and AdMobViewController just facilitate the needs of the sample app.
class AdMobViewController: DemandViewController {
convenience init(headerTitle: String, headerSubTitle: String) {
self.init(network: .admob, headerTitle: headerTitle, headerSubTitle: headerSubTitle)
}
}
Loading

0 comments on commit 0b251eb

Please sign in to comment.