8.5 C
Canberra
Tuesday, July 22, 2025

swift – Native adverts in flutter iOS NativeAdFactory will not be in scope


I’m following the google codelab for including native adverts in flutter for android and ios. For android it’s working correctly. However after I run the iOS app, it offers me error that the “NativeAdFactory” will not be in scope

AppDelegate.swift

import Flutter
import UIKit

import google_mobile_ads

@primary
@objc class AppDelegate: FlutterAppDelegate {
  override func utility(
    _ utility: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    let nativeInlineAdFactory = NativeInlineAdFactory()
    FLTGoogleMobileAdsPlugin.registerNativeAdFactory(
        self, factoryId: "nativeInlineAd", nativeAdFactory: nativeInlineAdFactory)

    return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
  }
}

And Native advert manufacturing facility is in similar runner folder is as follows:

import google_mobile_ads

class NativeInlineAdFactory : FLTNativeAdFactory {

    func createNativeAd(_ nativeAd: GADNativeAd,
                        customOptions: [AnyHashable : Any]? = nil) -> GADNativeAdView? {
        let nibView = Bundle.primary.loadNibNamed("NativeInlineAdView", proprietor: nil, choices: nil)!.first
        let nativeAdView = nibView as! GADNativeAdView

        (nativeAdView.headlineView as! UILabel).textual content = nativeAd.headline

        (nativeAdView.bodyView as! UILabel).textual content = nativeAd.physique
        nativeAdView.bodyView!.isHidden = nativeAd.physique == nil

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

        nativeAdView.callToActionView?.isUserInteractionEnabled = false

        nativeAdView.nativeAd = nativeAd

        return nativeAdView
    }
}

How can I repair this problem?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles