这个SwiftUI-Kit是一个开源项目,作为展示所有 SwiftUI 组件的一种方式,它支持所有 Apple 平台。
该项目是在 Xcode 12 测试版中创建的,使用新的 SwiftUIApp
协议来处理应用程序的生命周期,部署目标是 iOS 14。
现在,我想在项目中添加对 iOS 13 的支持。而且我找不到在这个项目中同时拥有App
适用于 iOS 14 和其他平台的协议并AppDelegate
用于 iOS 13 的方法。
我尝试了 App Delegate 和 Scene Delegate 方法的不同组合。最终结果是 iOS 13 设备崩溃并出现以下错误。
dyld: Symbol not found: _$s7SwiftUI4ViewPAAE18navigationBarTitle_11displayModeQrqd___AA010NavigationE4ItemV0f7DisplayH0OtSyRd__lFQOMQ
Referenced from: /private/var/containers/Bundle/Application/0813D699-9718-4106-BBC6/SwiftUI Kit iOS.app/SwiftUI Kit iOS
Expected in: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
in /private/var/containers/Bundle/Application/0813D699-9718-4106-BBC6/SwiftUI Kit iOS.app/SwiftUI Kit iOS
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
这是代码。您可以在此分支中找到 iOS 13 的完整项目代码。
import UIKit
import SwiftUI
#if os(iOS)
class AppDelegate: UIResponder, UIApplicationDelegate {...}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// ...
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
func sceneDidDisconnect(_ scene: UIScene) {...}
func sceneDidBecomeActive(_ scene: UIScene) {...}
func sceneWillResignActive(_ scene: UIScene) {...}
func sceneWillEnterForeground(_ scene: UIScene) {...}
func sceneDidEnterBackground(_ scene: UIScene) {...}
}
@main
struct MainApp {
static func main() {
if #available(iOS 14.0, *) {
SwiftUI_Kit_iOS_App.main()
} else {
UIApplicationMain(
CommandLine.argc,
CommandLine.unsafeArgv,
nil,
NSStringFromClass(AppDelegate.self)
)
}
}
}
@available(iOS 14.0, *)
struct SwiftUI_Kit_iOS_App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
#else
@main
struct SwiftUI_KitApp: App {
var body: some Scene {
WindowGroup {
#if os(macOS)
ContentView().frame(minWidth: 100, idealWidth: 300, maxWidth: .infinity, minHeight: 100, idealHeight: 200, maxHeight: .infinity)
#else
ContentView()
#endif
}
}
}
#endif
我查了这个问题,但答案需要 iOS 14 作为目标。我想让它以 iOS 13 为目标。