I am following the google codelab for adding native ads in flutter for android and ios. For android it is working properly. But when I run the iOS app, it gives me error that the "NativeAdFactory" is not in scope
AppDelegate.swift
import Flutter
import UIKit
import google_mobile_ads
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let nativeInlineAdFactory = NativeInlineAdFactory()
FLTGoogleMobileAdsPlugin.registerNativeAdFactory(
self, factoryId: "nativeInlineAd", nativeAdFactory: nativeInlineAdFactory)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
And Native ad factory is in same runner folder is as follows:
import google_mobile_ads
class NativeInlineAdFactory : FLTNativeAdFactory {
func createNativeAd(_ nativeAd: GADNativeAd,
customOptions: [AnyHashable : Any]? = nil) -> GADNativeAdView? {
let nibView = Bundle.main.loadNibNamed("NativeInlineAdView", owner: nil, options: nil)!.first
let nativeAdView = nibView as! GADNativeAdView
(nativeAdView.headlineView as! UILabel).text = nativeAd.headline
(nativeAdView.bodyView as! UILabel).text = nativeAd.body
nativeAdView.bodyView!.isHidden = nativeAd.body == nil
(nativeAdView.iconView as! UIImageView).image = nativeAd.icon?.image
nativeAdView.iconView!.isHidden = nativeAd.icon == nil
nativeAdView.callToActionView?.isUserInteractionEnabled = false
nativeAdView.nativeAd = nativeAd
return nativeAdView
}
}
How can I fix this issue?
So the problems was I added Swift files in VSCode and it was not added in the scope of the project in ios. Open the project in xcode and added those files in scope fixed the issue