iOS 14 Widgets + SwiftUI + Firebase?

后端 未结 3 1291
旧巷少年郎
旧巷少年郎 2020-12-31 21:17

I\'m still pretty new to SwiftUI and Firebase. Recently, as a hobby, I have been developing an app for my school. After the launch of Xcode 12, I decided to experiment with

3条回答
  •  北海茫月
    2020-12-31 21:54

    You can add the appDelegate to your @main SwiftUI view

    First create your appdelegate on your widget extension

    import Firebase
    
    class AppDelegate: NSObject, UIApplicationDelegate {
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
            FirebaseApp.configure()
            return true
        }
    }
    

    look at @main, inside your widget extension,

    @main
    struct TestWidget: Widget {
        @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
        private let kind: String = "ExampleWidget"
    
        public var body: some WidgetConfiguration {
           ...
        }
    }
    

    @main is new swift 5.3 feature that allows value type entry point, so this is will be your main entry point for your widget extension

    just add @UIApplciationDelegateAdaptor, inside your @main

提交回复
热议问题