AsyncStream Delegate with DependencyKey #1732
Replies: 1 comment 1 reply
-
Error is caused by using await in closure which don't provide asynchronous context. AsyncStream build closure is not async one. BTW why do you trying await However when I need to listen to UIApplicationDelegate method I use totally different approach. I use AppDelegate as my main point for setting up App's RootReducer and then just send action from methods. It looks like this. Delegate public class AppDelegate: NSObject, UIApplicationDelegate {
public var store: Store<HelperFeature.State, HelperFeature.Action>
lazy var viewStore = ViewStore(store.stateless)
public override init() {
self.store = StoreOf<HelperFeature>(
initialState: .init(showingDebugFields: true),
reducer: HelperFeature()
)
super.init()
}
public func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
viewStore.send(.appDidFinishLaunching)
return true
}
public func applicationWillTerminate(_ application: UIApplication) {
viewStore.send(.appWillTerminate)
}
} App Entry Point @main
struct MusicDisplayHelperApp: App {
@UIApplicationDelegateAdaptor var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
HelperView(store: appDelegate.store)
}
}
} BTW in my case delegate lives in separate module. All reacting to action called from AppDelegate is done in Reducer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am using firebase cloud messaging for notifications in my SwiftUI app. I need to handle UIApplicationDelegate's
didRegisterForRemoteNotificationsWithDeviceToken
to register the token. My code base is modularized and my firebase dependency is split between a test and live dependency following the videos you released on the topic. It has been working really nicely and has made development with previews a breeze.I need to use AsyncStream to intercept events to the UIApplicationDelegate methods. I am not sure if what i have is the best way to do this.
In my FireBaseClient interface i define:
In the module with my live implementation i add:
And I set the
delegate
inliveValue
as:Currently this is giving me an error:
But another question would be is this even correct? Will this override the AppDelegate implementation of
UIApplicationDelegate
?I guess the underlying question is how can i get access to those methods without having to import the dependencies into AppDelegate
Thanks
Beta Was this translation helpful? Give feedback.
All reactions