feat: 初始化 iOS 远程控制端项目
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import UIKit
|
||||
|
||||
/// UIKit 应用入口(UIKit 生命周期 + SwiftUI 内容视图混合架构)
|
||||
@main
|
||||
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func application(_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// 远程控制期间保持屏幕常亮
|
||||
application.isIdleTimerDisabled = true
|
||||
return true
|
||||
}
|
||||
|
||||
// MARK: - UISceneSession Lifecycle
|
||||
|
||||
func application(_ application: UIApplication,
|
||||
configurationForConnecting connectingSceneSession: UISceneSession,
|
||||
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
|
||||
let config = UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
|
||||
config.delegateClass = SceneDelegate.self
|
||||
return config
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
/// 场景代理:以 UIHostingController 承载 SwiftUI 根视图(UIKit 与 SwiftUI 混用)
|
||||
final 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 }
|
||||
|
||||
let window = UIWindow(windowScene: windowScene)
|
||||
let hosting = UIHostingController(rootView: ContentView())
|
||||
hosting.view.backgroundColor = .black
|
||||
window.rootViewController = hosting
|
||||
window.makeKeyAndVisible()
|
||||
self.window = window
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user