iOS_Swift AppWall, Native - adxcorp/ADXLibrary_Integration GitHub Wiki

AppWall Integration

AppWall 용으로 발급드린 App ID와 Unit ID를 사용하여 아래와 같이 구현해주시면 됩니다.

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 Integration

1) Native Ad Custom View

Native 광고의 필수 구성 요소로는 Icon Image, Title Text, CTA Button, Sponsored(AD) Tag, Privacy Icon 이 있습니다. 이 요소들은 반드시 포함하여 구성하여 주시고, 광고 컨텐츠를 덮는 View 가 없어야 합니다. 또한 텍스트 변경, 이미지 변경, 터치시 액션 변경 등 광고 컨텐츠에 관련된 부분을 가공하거나 변경하지 않도록 주의 부탁드립니다.

NativeAdView.swift

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
    }
}

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    NativeAdFactory.sharedInstance().setRenderingViewClass(<YOUR_ADUNIT_ID_HERE>, renderingViewClass: NativeAdView.self)
    return true
}

2) 하나의 View로 사용하실 경우

MyViewController.swift

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!) {
        
    }
}

3) TableView, CollectionView에서 Placer를 사용하시는 경우

Placer를 사용하시는 경우 Cell의 position 정보가 달라지기 때문에, TableView는 MPTableViewAdPlacer, CollectionView는 MPCollectionViewAdPlacer의 header 파일을 참고하시어 대체 method를 사용해주시기 바랍니다.

ex)
  setDelegate -> mp_setDelegate
  reloadData -> mp_reloadData 

MyViewController.swift

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
    }

    ...
}
⚠️ **GitHub.com Fallback** ⚠️