Files
Sportstime/SportsTime/Core/Services/AppDelegate.swift
Trey t 91c5eac22d fix: codebase audit fixes — safety, accessibility, and production hygiene
Address 16 issues from external audit:
- Move StoreKit transaction listener ownership to StoreManager singleton with proper deinit
- Remove noisy VoiceOver announcements, add missing accessibility on StatPill and BootstrapLoadingView
- Replace String @retroactive Identifiable with IdentifiableShareCode wrapper
- Add crash guard in AchievementEngine getContributingVisitIds + cache stadium lookups
- Pre-compute GamesHistoryViewModel filtered properties to avoid redundant SwiftUI recomputation
- Remove force-unwraps in ProgressMapView with safe guard-let fallback
- Add diff-based update gating in ItineraryTableViewWrapper to prevent unnecessary reloads
- Replace deprecated UIScreen.main with UIWindowScene lookup
- Add deinit task cancellation in ScheduleViewModel and SuggestedTripsGenerator
- Wrap ~234 unguarded print() calls across 27 files in #if DEBUG

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 00:07:53 -06:00

70 lines
2.3 KiB
Swift

//
// AppDelegate.swift
// SportsTime
//
// Handles push notification registration and CloudKit subscription notifications
//
import UIKit
import CloudKit
import UserNotifications
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// Register for remote notifications (required for CloudKit subscriptions)
application.registerForRemoteNotifications()
return true
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
#if DEBUG
print("📡 [Push] Registered for remote notifications")
#endif
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
#if DEBUG
print("📡 [Push] Failed to register: \(error.localizedDescription)")
#endif
}
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
guard let notification = CKNotification(fromRemoteNotificationDictionary: userInfo) as? CKQueryNotification,
let subscriptionID = notification.subscriptionID,
CloudKitService.canonicalSubscriptionIDs.contains(subscriptionID),
let recordType = CloudKitService.recordType(forSubscriptionID: subscriptionID) else {
completionHandler(.noData)
return
}
Task { @MainActor in
var changed = false
if notification.queryNotificationReason == .recordDeleted,
let recordID = notification.recordID {
changed = await BackgroundSyncManager.shared.applyDeletionHint(
recordType: recordType,
recordName: recordID.recordName
)
}
let updated = await BackgroundSyncManager.shared.triggerSyncFromPushNotification(subscriptionID: subscriptionID)
completionHandler((changed || updated) ? .newData : .noData)
}
}
}