This SwiftUI-Kit is a open source project, which acts as a way for showcasing all SwiftUI components and it supports all Apple platforms.
The project was created in Xcode 12 beta, with the new SwiftUI App
protocol for handling the app's lifecycle and the deployment target being iOS 14.
Now, I want to add Support for iOS 13 to the project. And I can't find a way to have both App
protocol for iOS 14 and other platforms and use AppDelegate
for iOS 13 in this project.
I tried different combinations of App Delegate and Scene Delegate methods. The end result is a crash in iOS 13 device with the following error.
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
Here is the code. You can find full project code for iOS 13 in this branch.
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
I looked up this question, but the answers require iOS 14 as target. I want to make it work with iOS 13 as target.