Files
Reflect/Shared/AppDelegate.swift
Trey t f2c510de50 Refactor StoreKit 2 subscription system and add interactive vote widget
## StoreKit 2 Refactor
- Rewrote IAPManager with clean enum-based state model (SubscriptionState)
- Added native SubscriptionStoreView for iOS 17+ purchase UI
- Subscription status now checked on every app launch
- Synced subscription status to UserDefaults for widget access
- Simplified PurchaseButtonView and IAPWarningView
- Removed unused StatusInfoView

## Interactive Vote Widget
- New FeelsVoteWidget with App Intents for mood voting
- Subscribers can vote directly from widget, shows stats after voting
- Non-subscribers see "Tap to subscribe" which opens subscription store
- Added feels:// URL scheme for deep linking

## Firebase Removal
- Commented out Firebase imports and initialization
- EventLogger now prints to console in DEBUG mode only

## Other Changes
- Added fallback for Core Data when App Group unavailable
- Added new localization strings for subscription UI
- Updated entitlements and Info.plist

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 23:07:16 -06:00

81 lines
3.6 KiB
Swift

//
// AppDelegate.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/10/22.
//
import Foundation
import UserNotifications
import UIKit
import WidgetKit
import SwiftUI
// import Firebase // Firebase removed
class AppDelegate: NSObject, UIApplicationDelegate {
private let savedOnboardingData = UserDefaultsStore.getOnboarding()
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// PersistenceController.shared.clearDB()
// PersistenceController.shared.deleteLast(numberOfEntries: 5)
// PersistenceController.shared.deleteRandomFromLast(numberOfEntries: 10)
// GroupUserDefaults.groupDefaults.set(false, forKey: UserDefaultsStore.Keys.showNSFW.rawValue)
// FirebaseApp.configure() // Firebase removed
PersistenceController.shared.removeNoForDates()
PersistenceController.shared.fillInMissingDates()
UNUserNotificationCenter.current().delegate = self
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(textColor)
UIPageControl.appearance().pageIndicatorTintColor = UIColor.systemGray
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
EventLogger.log(event: "app_launced")
return true
}
func applicationWillEnterForeground(_ application: UIApplication) {
PersistenceController.shared.fillInMissingDates()
// reschedule notifications so there's a new title next notification
LocalNotification.rescheduleNotifiations()
EventLogger.log(event: "app_foregorund")
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func requestAuthorization() { }
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.badge, .banner, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if let action = LocalNotification.ActionType(rawValue: response.actionIdentifier) {
let date = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: savedOnboardingData)
switch action {
case .horrible:
PersistenceController.shared.add(mood: .horrible, forDate: date, entryType: .notification)
case .bad:
PersistenceController.shared.add(mood: .bad, forDate: date, entryType: .notification)
case .average:
PersistenceController.shared.add(mood: .average, forDate: date, entryType: .notification)
case .good:
PersistenceController.shared.add(mood: .good, forDate: date, entryType: .notification)
case .great:
PersistenceController.shared.add(mood: .great, forDate: date, entryType: .notification)
}
UIApplication.shared.applicationIconBadgeNumber = 0
}
WidgetCenter.shared.reloadAllTimelines()
completionHandler()
}
}