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

报告相同问题?

悬赏问题

  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 C++行情软件的tick数据如何高效的合成K线
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。
  • ¥20 在easyX库下编写C语言扑克游戏跑的快,能实现简单的人机对战
  • ¥15 svpwm波形异常求解答
  • ¥15 STM32——硬件IIC从机通信代码实现
  • ¥15 微生物组数据分析--微生物代谢物