fix: comprehensive codebase hardening — crashes, silent failures, performance, and security
Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,17 @@ final class AnalyticsManager {
|
||||
|
||||
// MARK: - Configuration
|
||||
|
||||
private static let apiKey = "phc_RnF7XWdPeAY1M8ABAK75KlrOGVFfqHtZbkUuZ7oY8Xm"
|
||||
// TODO: Move to xcconfig/Info.plist before production
|
||||
private static let apiKey: String = {
|
||||
if let key = Bundle.main.infoDictionary?["POSTHOG_API_KEY"] as? String, !key.isEmpty {
|
||||
return key
|
||||
}
|
||||
#if DEBUG
|
||||
return "phc_development_key" // Safe fallback for debug builds
|
||||
#else
|
||||
fatalError("Missing POSTHOG_API_KEY in Info.plist")
|
||||
#endif
|
||||
}()
|
||||
private static let host = "https://analytics.88oakapps.com"
|
||||
private static let optOutKey = "analyticsOptedOut"
|
||||
private static let sessionReplayKey = "analytics_session_replay_enabled"
|
||||
@@ -102,8 +112,9 @@ final class AnalyticsManager {
|
||||
// Load selected sports from UserDefaults
|
||||
let selectedSports = UserDefaults.standard.stringArray(forKey: "selectedSports") ?? Sport.supported.map(\.rawValue)
|
||||
|
||||
// Keep super-property keys aligned with Feels so dashboards can compare apps 1:1.
|
||||
// SportsTime-specific super properties for dashboard segmentation.
|
||||
PostHogSDK.shared.register([
|
||||
"app_name": "SportsTime",
|
||||
"app_version": version,
|
||||
"build_number": build,
|
||||
"device_model": device,
|
||||
@@ -111,16 +122,6 @@ final class AnalyticsManager {
|
||||
"is_pro": isPro,
|
||||
"animations_enabled": animationsEnabled,
|
||||
"selected_sports": selectedSports,
|
||||
"theme": "n/a",
|
||||
"icon_pack": "n/a",
|
||||
"voting_layout": "n/a",
|
||||
"day_view_style": "n/a",
|
||||
"mood_shape": "n/a",
|
||||
"personality_pack": "n/a",
|
||||
"privacy_lock_enabled": false,
|
||||
"healthkit_enabled": false,
|
||||
"days_filter_count": 0,
|
||||
"days_filter_all": false,
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user