队长小楠
2019-12-16 21:05
采纳率: 100%
浏览 1.1k
已采纳

Flutter ios原生开发添加广点通开屏广告,进入flutter后无法加载插件?

想要给项目添加开屏广告,但是没有广点通的相关插件,所以只能从原生那里入手。
想法是在进入flutter界面前,添加一个开屏,开屏结束后进入flutter
根据 https://github.com/gdtmobsdk/GDTMobSDK 配置好sdk后
仿照 https://github.com/gdtmobsdk/GDTMobSDK/blob/v4.11.1/GDTMobSample-Swift/AppDelegate.swift 写了自己的AppDelegate.swift 如下

出现的问题是,能够正常显示开屏广告,显示完毕后也能进入flutter,但是flutter所有的第三方插件全部失效,报错是没有找到插件。

AppDelegate.swift

import UIKit
import Flutter


@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    var splash: GDTSplashAd!
    var flutterViewController: FlutterViewController?
    var flutterEngine : FlutterEngine?;


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

    GeneratedPluginRegistrant.register(with: self)

    self.flutterViewController = FlutterViewController()

    window = UIWindow.init(frame: UIScreen.main.bounds)
    let rootViewController = GDTNavigationController.init(rootViewController: self.flutterViewController!)
    rootViewController.navigationBar.isHidden = true
    rootViewController.navigationBar.isTranslucent = true

    window?.rootViewController = rootViewController
    window.makeKeyAndVisible()


    if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone {
        splash = GDTSplashAd.init(appId: Constant.appID, placementId: Constant.placementID)
        splash.delegate = self as? GDTSplashAdDelegate

        var splashImage = UIImage(named: "SplashNormal-swift")
        if Util.isIphoneX() {
            splashImage = UIImage(named: "SplashX-swift")
        } else if Util.isSmallIphone() {
            splashImage = UIImage(named: "SplashSmall-swift")
        }
        splash.backgroundImage = splashImage
        splash.fetchDelay = 3
        splash.loadAndShow(in: window)
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

为了方便查看贴上图片代码:
图片说明

p.s flutter正常生成的代码(未改造前的):

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dabocaiqq 2019-12-17 00:14
    已采纳
    点赞 打赏 评论

相关推荐 更多相似问题