Skip to content

Commit

Permalink
Invalid FCM token fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaferis committed Jun 13, 2024
1 parent 6dbaf1e commit ff8ead8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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

0 comments on commit ff8ead8

Please sign in to comment.