队长小楠 2019-12-16 21:05 采纳率: 50%
浏览 1123
已采纳

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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?