Corrige toggle do lembrete diário que não ligava
- Re-verifica a permissão de notificações quando o app volta ao primeiro plano (scenePhase), refletindo mudanças feitas nos Ajustes do iPhone - Toggle otimista: liga imediatamente ao toque e reverte apenas se a autorização for negada - Prompt inicial completa a ativação sozinho ao voltar dos Ajustes com a permissão concedida - Novo teste de UI: ativar o lembrete pelo toggle das configurações Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import UserNotifications
|
||||
struct PlanSettingsView: View {
|
||||
@Bindable var plan: ReadingPlanState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
@State private var authorizationStatus: UNAuthorizationStatus = .notDetermined
|
||||
@State private var showRestartConfirmation = false
|
||||
@@ -29,8 +30,14 @@ struct PlanSettingsView: View {
|
||||
Button("OK") { dismiss() }
|
||||
}
|
||||
}
|
||||
.task {
|
||||
// Re-verifica a permissão sempre que o app volta ao primeiro plano —
|
||||
// essencial para refletir mudanças feitas nos Ajustes do iPhone.
|
||||
.task(id: scenePhase) {
|
||||
guard scenePhase == .active else { return }
|
||||
authorizationStatus = await ReadingReminderService.authorizationStatus()
|
||||
if authorizationStatus == .authorized, plan.reminderEnabled {
|
||||
await ReadingReminderService.refresh(for: plan)
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Reiniciar o plano do dia 1? Seu progresso atual será apagado, mas a preferência de lembrete será mantida.",
|
||||
@@ -83,6 +90,9 @@ struct PlanSettingsView: View {
|
||||
plan.reminderEnabled
|
||||
} set: { newValue in
|
||||
if newValue {
|
||||
// Otimista: liga já, para o switch responder ao toque;
|
||||
// reverte se a autorização for negada.
|
||||
plan.reminderEnabled = true
|
||||
Task {
|
||||
let status = await ReadingReminderService.authorizationStatus()
|
||||
var granted = status == .authorized || status == .provisional
|
||||
@@ -90,7 +100,6 @@ struct PlanSettingsView: View {
|
||||
granted = (try? await ReadingReminderService.requestAuthorization()) ?? false
|
||||
}
|
||||
if granted {
|
||||
plan.reminderEnabled = true
|
||||
await ReadingReminderService.refresh(for: plan)
|
||||
} else {
|
||||
plan.reminderEnabled = false
|
||||
|
||||
@@ -226,6 +226,7 @@ struct ReadingPlanView: View {
|
||||
struct ReminderPromptSheet: View {
|
||||
@Bindable var plan: ReadingPlanState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
@State private var time: Date = Calendar.current.date(bySettingHour: 20, minute: 0, second: 0, of: .now) ?? .now
|
||||
@State private var showDeniedInfo = false
|
||||
@@ -277,6 +278,14 @@ struct ReminderPromptSheet: View {
|
||||
.padding(.bottom, 16)
|
||||
.presentationDetents([.large])
|
||||
.interactiveDismissDisabled(false)
|
||||
// Se o usuário foi aos Ajustes e habilitou as notificações,
|
||||
// completa a ativação automaticamente ao voltar para o app.
|
||||
.task(id: scenePhase) {
|
||||
guard scenePhase == .active, showDeniedInfo else { return }
|
||||
if await ReadingReminderService.authorizationStatus() == .authorized {
|
||||
activateReminder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func activateReminder() {
|
||||
|
||||
Reference in New Issue
Block a user