From 7ee8f39114e85df1c7b5401308c6f5bdf5568071 Mon Sep 17 00:00:00 2001 From: tomokisun Date: Sun, 15 Oct 2023 20:20:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20request=20notify=20after?= =?UTF-8?q?=20add=20friends?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Packages/GodPackage/Package.swift | 2 ++ .../GodPackage/Sources/AppFeature/AppDelegate.swift | 5 ----- .../Sources/HowItWorksFeature/HowItWorks.swift | 2 ++ .../Sources/OnboardFeature/OnboardPathLogic.swift | 12 ++++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Packages/GodPackage/Package.swift b/Packages/GodPackage/Package.swift index fd2f595d..a879aa34 100644 --- a/Packages/GodPackage/Package.swift +++ b/Packages/GodPackage/Package.swift @@ -155,7 +155,9 @@ let package = Package( .product(name: "RoundedCorner", package: "UIComponentPackage"), .product(name: "AnalyticsClient", package: "DependencyPackage"), .product(name: "UserDefaultsClient", package: "CupertinoPackage"), + .product(name: "UIApplicationClient", package: "CupertinoPackage"), .product(name: "FirebaseAuthClient", package: "DependencyPackage"), + .product(name: "UserNotificationClient", package: "CupertinoPackage"), .product(name: "FirebaseStorageClient", package: "DependencyPackage"), .product(name: "PhoneNumberDependencies", package: "DependencyPackage"), .product(name: "CachedAsyncImage", package: "swiftui-cached-async-image"), diff --git a/Packages/GodPackage/Sources/AppFeature/AppDelegate.swift b/Packages/GodPackage/Sources/AppFeature/AppDelegate.swift index 5e203b07..618b35df 100644 --- a/Packages/GodPackage/Sources/AppFeature/AppDelegate.swift +++ b/Packages/GodPackage/Sources/AppFeature/AppDelegate.swift @@ -50,11 +50,6 @@ public struct AppDelegateLogic: Reducer { firebaseCore.configure() return .run { @MainActor send in await withThrowingTaskGroup(of: Void.self) { group in - group.addTask { - guard try await userNotifications.requestAuthorization([.alert, .sound, .badge]) - else { return } - await registerForRemoteNotifications() - } group.addTask { for await event in userNotifications.delegate() { await send(.userNotifications(event)) diff --git a/Packages/GodPackage/Sources/HowItWorksFeature/HowItWorks.swift b/Packages/GodPackage/Sources/HowItWorksFeature/HowItWorks.swift index 0827567d..d1af7ade 100644 --- a/Packages/GodPackage/Sources/HowItWorksFeature/HowItWorks.swift +++ b/Packages/GodPackage/Sources/HowItWorksFeature/HowItWorks.swift @@ -21,6 +21,7 @@ public struct HowItWorksLogic: Reducer { public enum Delegate: Equatable { case start + case notifyRequest } } @@ -35,6 +36,7 @@ public struct HowItWorksLogic: Reducer { switch action { case .onTask: return .run { send in + await send(.delegate(.notifyRequest)) for try await data in godClient.currentUser() { await send(.currentUserResponse(.success(data))) } diff --git a/Packages/GodPackage/Sources/OnboardFeature/OnboardPathLogic.swift b/Packages/GodPackage/Sources/OnboardFeature/OnboardPathLogic.swift index 2ec17f5f..e9361f07 100644 --- a/Packages/GodPackage/Sources/OnboardFeature/OnboardPathLogic.swift +++ b/Packages/GodPackage/Sources/OnboardFeature/OnboardPathLogic.swift @@ -5,6 +5,8 @@ import ContactsClient import God import GodClient import UserDefaultsClient +import UserNotificationClient +import UIApplicationClient public struct OnboardPathLogic: Reducer { @Dependency(\.analytics) var analytics @@ -31,6 +33,9 @@ public struct OnboardPathLogic: Reducer { await send(.contactResponse(.failure(error))) } } + + @Dependency(\.userNotifications.requestAuthorization) var requestAuthorization + @Dependency(\.application.registerForRemoteNotifications) var registerForRemoteNotifications public func reduce( into state: inout OnboardLogic.State, @@ -136,6 +141,13 @@ public struct OnboardPathLogic: Reducer { case .addFriends(.delegate(.nextScreen)): state.path.append(.howItWorks()) return .none + + case .howItWorks(.delegate(.notifyRequest)): + return .run { send in + guard try await requestAuthorization([.alert, .sound, .badge]) + else { return } + await registerForRemoteNotifications() + } case .howItWorks(.delegate(.start)): // オンボーディングすべて終わり