Skip to content

Instantly share code, notes, and snippets.

@huxaiphaer
Created August 30, 2020 18:41
Show Gist options
  • Save huxaiphaer/25a22015a2082396a3a00710048d49af to your computer and use it in GitHub Desktop.
Save huxaiphaer/25a22015a2082396a3a00710048d49af to your computer and use it in GitHub Desktop.
import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, UIResponder, UIApplicationDelegate {
var window: UIWindow?
var application: UIApplication?
var unityController: UnityAppController?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func startUnity()
{
isShowUnityWindow = !isShowUnityWindow
var appDelegate = UIApplication.shared.delegate as? AppDelegate
if isShowUnityWindow {
appDelegate?.unityWindow()!.frame = CGRect(x: 10, y: 70, width: 350, height: 300)
appDelegate?.showUnityWindow()
} else {
// appDelegate?.hideUnityWindow()
}
}
func unityWindow() -> UIWindow? {
return UnityGetMainWindow()
}
func showUnityWindow() {
unityWindow()?.makeKeyAndVisible()
}
func hideUnityWindow() {
window!.makeKeyAndVisible()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Override point for customization after application launch.
sleep(3)
self.application = application
unity_init(CommandLine.argc, CommandLine.unsafeArgv)
unityController = UnityAppController()
unityController!.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func applicationWillResignActive(_ application: UIApplication) {
unityController!.applicationWillResignActive(application)
}
func applicationDidEnterBackground(_ application: UIApplication) {
unityController!.applicationDidEnterBackground(application)
}
func applicationWillEnterForeground(_ application: UIApplication) {
unityController!.applicationWillEnterForeground(application)
}
func applicationDidBecomeActive(_ application: UIApplication) {
unityController!.applicationDidBecomeActive(application)
}
func applicationWillTerminate(_ application: UIApplication) {
unityController!.applicationWillTerminate(application)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment