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>
This commit is contained in:
@@ -1,69 +1,57 @@
|
||||
//
|
||||
// PurchaseButtonView.swift
|
||||
// IAPWarningView.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 7/7/22.
|
||||
// Trial warning banner shown at bottom of Month/Year views.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import StoreKit
|
||||
|
||||
struct IAPWarningView: View {
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
@AppStorage(UserDefaultsStore.Keys.firstLaunchDate.rawValue, store: GroupUserDefaults.groupDefaults) private var firstLaunchDate = Date()
|
||||
|
||||
var iapManager: IAPManager
|
||||
|
||||
private let height: Float
|
||||
private let showManageSubClosure: (() -> Void)?
|
||||
|
||||
@State private var showSettings = false
|
||||
|
||||
public init(height: Float, iapManager: IAPManager, showManageSubClosure: (() -> Void)? = nil, showCountdownTimer: Bool = false) {
|
||||
self.height = height
|
||||
self.showManageSubClosure = showManageSubClosure
|
||||
self.iapManager = iapManager
|
||||
}
|
||||
|
||||
|
||||
@ObservedObject var iapManager: IAPManager
|
||||
|
||||
@State private var showSubscriptionStore = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let date = Calendar.current.date(byAdding: .day, value: 30, to: firstLaunchDate) {
|
||||
VStack(spacing: 8) {
|
||||
HStack {
|
||||
Image(systemName: "clock")
|
||||
.foregroundColor(.orange)
|
||||
|
||||
Text(String(localized: "iap_warning_view_title"))
|
||||
.font(.body)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.background(theme.currentTheme.secondaryBGColor)
|
||||
|
||||
Text(date, style: .relative)
|
||||
.font(.body)
|
||||
.bold()
|
||||
.foregroundColor(textColor)
|
||||
|
||||
Button(action: {
|
||||
showSettings.toggle()
|
||||
}, label: {
|
||||
Text(String(localized: "iap_warning_view_buy_button"))
|
||||
.foregroundColor(.white)
|
||||
|
||||
if let expirationDate = iapManager.trialExpirationDate {
|
||||
Text(expirationDate, style: .relative)
|
||||
.font(.body)
|
||||
.bold()
|
||||
.frame(maxWidth: .infinity)
|
||||
.contentShape(Rectangle())
|
||||
})
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 50)
|
||||
.background(RoundedRectangle(cornerRadius: 10).fill(DefaultMoodTint.color(forMood: .great)))
|
||||
.foregroundColor(.orange)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
showSubscriptionStore = true
|
||||
} label: {
|
||||
Text(String(localized: "iap_warning_view_buy_button"))
|
||||
.font(.headline)
|
||||
.foregroundColor(.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(RoundedRectangle(cornerRadius: 10).fill(Color.pink))
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.padding()
|
||||
.background(theme.currentTheme.secondaryBGColor)
|
||||
.sheet(isPresented: $showSettings) {
|
||||
SettingsView()
|
||||
.sheet(isPresented: $showSubscriptionStore) {
|
||||
FeelsSubscriptionStoreView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct IAPWarningView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
IAPWarningView(height: 175, iapManager: IAPManager())
|
||||
}
|
||||
#Preview {
|
||||
IAPWarningView(iapManager: IAPManager())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user