Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid FCM token fix #34

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ struct PushNotificationsSettingsView: View {
if #available(iOS 15, *) {
pushNotificationsSettingsList()
.safeAreaInset(edge: .bottom) {
refreshTokenFooterView()
buttonsFooterView()
}
} else {
ZStack(alignment: .bottom) {
pushNotificationsSettingsList()
refreshTokenFooterView()
buttonsFooterView()
}
}

}
.navigationTitle("Push notifications settings")
.onAppear { viewModel.refreshToken(shouldRegenerate: false) }
.copiedAlert(isPresented: $viewModel.isShowingCopiedAlert)
.alert(isPresented: $viewModel.hasError) {
Alert(
Expand Down Expand Up @@ -80,9 +80,10 @@ private extension PushNotificationsSettingsView {
}.buttonStyle(.borderless)
}

func refreshTokenFooterView() -> some View {
ButtonFilled(text: "Refresh token") {
viewModel.refreshToken()
func buttonsFooterView() -> some View {
VStack(spacing: 8) {
ButtonFilled(text: "Reload token") { viewModel.refreshToken(shouldRegenerate: false) }
ButtonFilled(text: "Generate new token", style: .danger) { viewModel.refreshToken(shouldRegenerate: true) }
}
.padding(16)
.background(Glass().edgesIgnoringSafeArea(.bottom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ final class PushNotificationsSettingsViewModel: ObservableObject {

init(pushNotificationsProvider: PushNotificationsProvider) {
self.pushNotificationsProvider = pushNotificationsProvider
self.token = pushNotificationsProvider.token
}

}
Expand All @@ -41,11 +40,13 @@ extension PushNotificationsSettingsViewModel {
isShowingCopiedAlert = true
}
}
func refreshToken() {
Task {

func refreshToken(shouldRegenerate: Bool) {
Task { @MainActor in
do {
try await pushNotificationsProvider.deleteToken()
if shouldRegenerate {
try await pushNotificationsProvider.deleteToken()
}
token = try await pushNotificationsProvider.getToken()
} catch {
self.error = error
Expand Down