I don’t know how to check what happens if someone cancels their subscription I want them to go back to the MainOnboardingView. Your help would be highly appreciated. Here is the file where I make the check on what view to show. It is the main App file:
import SwiftUI
import SuperwallKit
Imagine “@” where it is supposed to be forum wouldn’t let me post the code otherwise
main
struct GospelApp: App {
StateObject private var prayerStreak = PrayerStreak()
StateObject private var notificationsManager = NotificationsManager.shared
AppStorage(“isFirstLaunch”) private var isFirstLaunch: Bool = true
AppStorage(“hasScheduledTestimonials”) private var hasScheduledTestimonials: Bool = false
Environment(.scenePhase) private var scenePhase
AppStorage(“isPremium”) var isPremium: Bool = false
init() {
Superwall.configure(apiKey: "[Redacted]")
}
var body: some Scene {
WindowGroup {
Group {
if isPremium {
MainTabView()
} else {
MainOnboardingView()
}
}
.environmentObject(prayerStreak)
.environmentObject(notificationsManager)
.onAppear {
if isFirstLaunch {
// Request notification permissions on first launch
notificationsManager.requestPermission { granted in
print("Notification permission granted: \(granted)")
// If user denies permissions, we won't be able to schedule the welcome notification
// in the requestPermission callback, so try again here
if granted && notificationsManager.notificationsEnabled {
notificationsManager.scheduleWelcomeNotification()
}
}
isFirstLaunch = false
} else {
// Check if we're in the second week and should schedule testimonial notifications
checkAndScheduleTestimonials()
}
}
.onChange(of: scenePhase) { oldPhase, newPhase in
if newPhase == .active {
// Reset the badge count when the app becomes active
notificationsManager.resetBadgeCount()
// Check notification authorization status
notificationsManager.checkAuthorizationStatus()
// Check if we're in the second week and should schedule testimonial notifications
checkAndScheduleTestimonials()
}
}
}
}
private func checkAndScheduleTestimonials() {
// First check if notifications are authorized and enabled
if !notificationsManager.isAuthorized || !notificationsManager.notificationsEnabled {
return
}
// If we haven't tried to schedule testimonials yet, check if we should
if !hasScheduledTestimonials {
// Let the NotificationsManager handle the logic of whether we're in the second week
notificationsManager.schedulePersonalNotifications()
hasScheduledTestimonials = true
}
}
}"