(EN) iOS_Swift AppWall, Native - adxcorp/ADXLibrary_Integration GitHub Wiki
Use App ID and Unit ID that were issued for AppWall as follows:
override func viewDidLoad() {
super.viewDidLoad()
AppWallFactory.init("<YOUR_APP_ID>", adUnitId: "<YOUR_ADUNIT_ID>")
AppWallFactory.preloadAppWall()
}
@IBAction func selectShowAd(_ sender: Any) {
AppWallFactory.showAppWall(self)
}
Native Ad requires you to provide Icon Image, Title Text, CTA Button, Sponsored(AD) Tag, and Privacy Icon. Also, there must be no view that covers over ad content area. Finally, you are not allowed to change any text, image or touch actions related to the ad content.
import MoPub;
class NativeAdView: UIView, MPNativeAdRendering {
@IBOutlet var contentsView: UIView!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var mainTextLabel: UILabel!
@IBOutlet var callToActionLabel: UILabel!
@IBOutlet var iconImageView: UIImageView!
@IBOutlet var privacyInformationIconImageView: UIImageView!
@IBOutlet var mainImageView: UIImageView!
...
override func layoutSubviews () {
super.layoutSubviews()
}
func nativeMainTextLabel() -> UILabel {
return self.mainTextLabel
}
func nativeTitleTextLabel() -> UILabel {
return self.titleLabel
}
func nativeCallToActionTextLabel() -> UILabel {
return self.callToActionLabel
}
func nativeIconImageView() -> UIImageView {
return self.iconImageView
}
func nativeMainImageView() -> UIImageView {
return self.mainImageView
}
func nativePrivacyInformationIconImageView() -> UIImageView {
return self.privacyInformationIconImageView
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NativeAdFactory.sharedInstance().setRenderingViewClass(<YOUR_ADUNIT_ID_HERE>, renderingViewClass: NativeAdView.self)
return true
}
import MoPub
import ADXLibrary
class MyViewController: UIViewController, NativeAdFactoryDelegate, MPNativeAdDelegate {
var nativeAd:MPNativeAd?
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NativeAdFactory.sharedInstance().remove(self)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NativeAdFactory.sharedInstance().add(self)
NativeAdFactory.sharedInstance().loadAd(NATIVE_AD_UNIT_ID)
}
...
func viewControllerForPresentingModalView() -> UIViewController! {
return self
}
func onSuccess(_ adUnitId: String!, nativeAd: MPNativeAd!) {
if (adUnitId == NATIVE_AD_UNIT_ID) {
self.nativeAd = nativeAd
self.nativeAd?.delegate = self
let nativeAdView = NativeAdFactory.sharedInstance().getNativeAdView(NATIVE_AD_UNIT_ID)
nativeAdView?.frame = CGRect(x: (UIScreen.main.bounds.width - 300.0)/2
, y: 100.0
, width: 300.0
, height: 200.0)
self.view.addSubview(nativeAdView!)
} else {
}
}
func onFailure(_ adUnitId: String!) {
}
}
When using Placer
, Cell
position changes. So make sure to use alternative methods by referring to MPTableViewAdPlacer
header file in case of TableView
, and MPCollectionViewAdPlacer
header file in case of CollectionView
.
ex)
setDelegate -> mp_setDelegate
reloadData -> mp_reloadData
import UIKit
import ADXLibrary
class MyViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet var mainCollectionView: UICollectionView!
var placer : MPCollectionViewAdPlacer!
override func viewDidLoad() {
super.viewDidLoad()
self.placer = NativeAdFactory.sharedInstance().getCollectionViewAdPlacer(<YOUR_ADUNIT_ID_HERE>
, collectionView: self.mainCollectionView
, viewController: self
, viewSizeHandler: { (maximumWidth) -> CGSize in
let width : CGFloat
width = UIScreen.main.bounds.size.width;
return CGSize(width: width, height: floor(width * 0.5225))
})
self.placer.loadAds(forAdUnitID: <YOUR_ADUNIT_ID_HERE>)
}
...
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return <ITEM_COUNT>;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell : UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "<REUSE-IDENTIFIER>", for: indexPath)
return cell
}
...
}