iap work
This commit is contained in:
@@ -143,6 +143,11 @@ class IAPManager: ObservableObject {
|
||||
|
||||
public func updateEverything() {
|
||||
Task {
|
||||
DispatchQueue.main.async {
|
||||
self.subscriptions.removeAll()
|
||||
self.purchasedProductIDs.removeAll()
|
||||
}
|
||||
|
||||
// get current sub from local cache
|
||||
await updatePurchasedProducts()
|
||||
|
||||
@@ -365,6 +370,14 @@ class IAPManager: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public func restore() async {
|
||||
do {
|
||||
try await AppStore.sync()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
func checkVerified<T>(_ result: VerificationResult<T>) throws -> T {
|
||||
//Check whether the JWS passes StoreKit verification.
|
||||
switch result {
|
||||
|
||||
@@ -28,11 +28,15 @@ struct PurchaseButtonView: View {
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
switch iapManager.showIAP {
|
||||
// if we should show the iap warning that means no purchase which means
|
||||
// we should show buy options
|
||||
switch iapManager.showIAPWarning {
|
||||
case true:
|
||||
buyOptionsView
|
||||
.frame(height: CGFloat(height))
|
||||
.background(theme.currentTheme.secondaryBGColor)
|
||||
VStack {
|
||||
buyOptionsView
|
||||
.frame(height: CGFloat(height))
|
||||
.background(theme.currentTheme.secondaryBGColor)
|
||||
}
|
||||
case false:
|
||||
subscribedView
|
||||
.frame(height: CGFloat(height))
|
||||
|
||||
@@ -146,12 +146,26 @@ struct SettingsView: View {
|
||||
private var subscriptionInfoView: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: {
|
||||
Task {
|
||||
await
|
||||
self.showManageSubscription()
|
||||
VStack {
|
||||
PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: {
|
||||
Task {
|
||||
await
|
||||
self.showManageSubscription()
|
||||
}
|
||||
}, showCountdownTimer: true)
|
||||
|
||||
if iapManager.showIAPWarning {
|
||||
Button(action: {
|
||||
Task {
|
||||
await iapManager.restore()
|
||||
}
|
||||
}, label: {
|
||||
Text(String(localized: "purchase_view_restore"))
|
||||
.font(.title3)
|
||||
.padding([.top, .bottom])
|
||||
})
|
||||
}
|
||||
}, showCountdownTimer: true)
|
||||
}
|
||||
}
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
@@ -228,6 +242,7 @@ struct SettingsView: View {
|
||||
tmpDate = Calendar.current.date(byAdding: .minute, value: -59, to: tmpDate)!
|
||||
tmpDate = Calendar.current.date(byAdding: .second, value: -45, to: tmpDate)!
|
||||
firstLaunchDate = tmpDate
|
||||
iapManager.updateEverything()
|
||||
}, label: {
|
||||
Text("Set first launch date back 29 days, 23 hrs, 45 seconds")
|
||||
.foregroundColor(textColor)
|
||||
@@ -243,6 +258,7 @@ struct SettingsView: View {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
Button(action: {
|
||||
firstLaunchDate = Date()
|
||||
iapManager.updateEverything()
|
||||
}, label: {
|
||||
Text("Reset luanch date to current date")
|
||||
.foregroundColor(textColor)
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
"purchase_view_current_subscription_expires_in" = "Trial expires in:";
|
||||
"purchase_view_current_subscription_expired_on" = "Trial expired on:";
|
||||
"purchase_view_loading" = "Loading subscription options";
|
||||
"purchase_view_restore" = "Restore";
|
||||
|
||||
"iap_warning_view_title" = "This view will no longer scroll in ";
|
||||
"iap_warning_view_buy_button" = "Subscribe Now";
|
||||
|
||||
Reference in New Issue
Block a user