Skip to content

Commit

Permalink
User notification client fixes (#174)
Browse files Browse the repository at this point in the history
* fixed delegate deallocating

* assign UNUserNotificationCenter delegate before app finishes launching.

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information
tplaymeow and stephencelis committed Aug 23, 2023
1 parent f92cbd7 commit ed59ba8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/AppFeature/AppDelegate.swift
Expand Up @@ -30,10 +30,11 @@ public struct AppDelegateReducer: Reducer {
Reduce { state, action in
switch action {
case .didFinishLaunching:
let userNotificationsEventStream = self.userNotifications.delegate()
return .run { send in
await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
for await event in self.userNotifications.delegate() {
for await event in userNotificationsEventStream {
await send(.userNotifications(event))
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/ComposableUserNotifications/LiveKey.swift
Expand Up @@ -9,7 +9,9 @@ extension UserNotificationClient: DependencyKey {
AsyncStream { continuation in
let delegate = Delegate(continuation: continuation)
UNUserNotificationCenter.current().delegate = delegate
continuation.onTermination = { [delegate] _ in }
continuation.onTermination = { _ in
_ = delegate
}
}
},
getNotificationSettings: {
Expand Down

0 comments on commit ed59ba8

Please sign in to comment.