Adpluginx Documentation
  • 👋Welcome to AdPluginx
  • Installation
    • ⚙️Install Adpluginx
    • Configure Pod For Ios
    • Configure Info.plist
    • Configure SkAdNetworks
    • Configure AppDelegate
    • Creating Native AdView
    • Init Native View to Swift Class
    • Add Onesignal to Project
  • Ad Network Indexes
    • AdConfig
    • FullScreen Ad Indexes
    • Banner Ad Indexes
    • Native Ad Indexes
  • Apple SignIn & In App Purchase
    • Enable Apple SignIn And Use
    • Skip Logic
    • InApp Purchases
    • Coin Login
Powered by GitBook
On this page

Was this helpful?

  1. Installation

Init Native View to Swift Class

  1. Now Add Another file to Runner

  2. This time select Swift and name it SingisticNativeAdFactory

  3. Now open SingisticNativeAdFactory and replace it by below code.

SingisticNativeAdFactory.swift
import google_mobile_ads

import UIKit

class SingisticNativeAdFactory : FLTNativeAdFactory {

    func createNativeAd(_ nativeAd: GADNativeAd,
                        customOptions: [AnyHashable : Any]? = nil) -> GADNativeAdView? {
        let nibView = Bundle.main.loadNibNamed("NativeAdView", owner: nil, options: nil)!.first


        let nativeAdView = nibView as! GADNativeAdView

        (nativeAdView.headlineView as! UILabel).text = nativeAd.headline
        nativeAdView.headlineView!.isHidden = nativeAd.headline == nil


        (nativeAdView.bodyView as! UILabel).text = nativeAd.body
        nativeAdView.bodyView!.isHidden = nativeAd.body == nil

        (nativeAdView.callToActionView as! UIButton).setTitle(nativeAd.callToAction, for: .normal)
        nativeAdView.callToActionView!.isHidden = nativeAd.callToAction == nil

        (nativeAdView.iconView as! UIImageView).image = nativeAd.icon?.image
        nativeAdView.iconView!.isHidden = nativeAd.icon == nil

        (nativeAdView.storeView as! UILabel).text = nativeAd.store
        nativeAdView.storeView!.isHidden = nativeAd.store == nil

        (nativeAdView.priceView as! UILabel).text = nativeAd.price
        nativeAdView.priceView!.isHidden = nativeAd.price == nil

        (nativeAdView.advertiserView as! UILabel).text = nativeAd.advertiser
        nativeAdView.advertiserView!.isHidden = nativeAd.advertiser == nil

        nativeAdView.callToActionView?.isUserInteractionEnabled = false

        nativeAdView.nativeAd = nativeAd

        return nativeAdView
    }
}
PreviousCreating Native AdViewNextAdd Onesignal to Project

Last updated 2 years ago

Was this helpful?