Files
Reflect/Shared/AppDelegate.swift
Trey t 5b8a98f763 Fix feels://subscribe deep link on cold launch via app.open()
When XCUITest calls app.open(url), the app relaunches (cold launch) and
onOpenURL doesn't fire reliably. Capture the URL from launch options in
AppDelegate and check it on appear with a short delay to ensure the view
hierarchy is ready for sheet presentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 11:58:12 -06:00

74 lines
2.6 KiB
Swift

//
// AppDelegate.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/10/22.
//
import Foundation
import UserNotifications
import UIKit
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
static var pendingDeepLinkURL: URL?
private let savedOnboardingData = UserDefaultsStore.getOnboarding()
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@MainActor
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if let url = launchOptions?[.url] as? URL {
AppDelegate.pendingDeepLinkURL = url
}
DataController.shared.removeNoForDates()
DataController.shared.fillInMissingDates()
UNUserNotificationCenter.current().delegate = self
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(theme.currentTheme.labelColor)
UIPageControl.appearance().pageIndicatorTintColor = UIColor.systemGray
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
return true
}
}
extension AppDelegate: @preconcurrency UNUserNotificationCenterDelegate {
func requestAuthorization() { }
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.badge, .banner, .sound])
}
@MainActor
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)
let mood: Mood
switch action {
case .horrible:
mood = .horrible
case .bad:
mood = .bad
case .average:
mood = .average
case .good:
mood = .good
case .great:
mood = .great
}
// Use centralized mood logger
MoodLogger.shared.logMood(mood, for: date, entryType: .notification)
UNUserNotificationCenter.current().setBadgeCount(0)
}
completionHandler()
}
}