jonbhanson / flutter_native_splash

Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
https://pub.dev/packages/flutter_native_splash
MIT License
1.36k stars 215 forks source link

Using it with flutter_carplay will cause flutter_native_splash to fail #609

Closed zhushenwudi closed 10 months ago

zhushenwudi commented 1 year ago

Attention: If you open a bug report without sufficient details, it will be closed. Is your question related to Android 12? Please check the notes on Android 12 first (https://pub.dev/packages/flutter_native_splash#android-12-support).

Describe the bug I use flutter_carplay library on IOS. In order to use the carplay function without opening the app, you need to do the following for the ios startup class

import UIKit
import Flutter

let flutterEngine = FlutterEngine(name: "xxx", project: nil, allowHeadlessExecution: true)

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

And flutter initial move to SceneDelegate.swift

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }

        window = UIWindow(windowScene: windowScene)

        let controller = FlutterViewController.init(engine: flutterEngine, nibName: nil, bundle: nil)
        window?.rootViewController = controller
        window?.makeKeyAndVisible()
        controller.loadDefaultSplashScreenView()
    }
}

Configuration

flutter_native_splash:
   color: "ffffff"
   image: assets/launch/background.png
   android_12:
   android_gravity: center
   ios_content_mode: scaleAspectFit

Device (please complete the following information):

To Reproduce Steps to reproduce the behavior, using the example app:

  1. Rewrite normal swift to the code written above
  2. Open app
  3. See no splash screen

Screenshots No, but i can provide if you want

Additional context Only the first installation will have the screen opening interface, and each subsequent opening will only display the interface before the last destruction of the APP, and will no longer display the screen opening interface, and the change will enter the app after a while.

jonbhanson commented 11 months ago

Sorry @zhushenwudi I don't have any experience using flutter_carplay. Can you recommend how I need to update this plugin to make it compatible?

zhushenwudi commented 11 months ago

I have no idea. Currently, the flutter_carplay library does not support the car system to start activitiy first, so flutterEngine is initialized through a proxy in advance, which may destroy some life cycle methods of the flutter application. As a result, the splash interface can only be displayed when starting from the Apple phone for the first time. I wonder what your opinion is on this. After all, this is a very special situation. Even if it can be handled, the IOS side may need to reconsider the location of the splash statement.

jonbhanson commented 10 months ago

I don't think I can add any information to solving this since i don't have any experience with carplay. Sorry.

zhushenwudi commented 10 months ago

that's all right