iap work
This commit is contained in:
@@ -143,6 +143,11 @@ class IAPManager: ObservableObject {
|
|||||||
|
|
||||||
public func updateEverything() {
|
public func updateEverything() {
|
||||||
Task {
|
Task {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.subscriptions.removeAll()
|
||||||
|
self.purchasedProductIDs.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
// get current sub from local cache
|
// get current sub from local cache
|
||||||
await updatePurchasedProducts()
|
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 {
|
func checkVerified<T>(_ result: VerificationResult<T>) throws -> T {
|
||||||
//Check whether the JWS passes StoreKit verification.
|
//Check whether the JWS passes StoreKit verification.
|
||||||
switch result {
|
switch result {
|
||||||
|
|||||||
@@ -28,11 +28,15 @@ struct PurchaseButtonView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
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:
|
case true:
|
||||||
buyOptionsView
|
VStack {
|
||||||
.frame(height: CGFloat(height))
|
buyOptionsView
|
||||||
.background(theme.currentTheme.secondaryBGColor)
|
.frame(height: CGFloat(height))
|
||||||
|
.background(theme.currentTheme.secondaryBGColor)
|
||||||
|
}
|
||||||
case false:
|
case false:
|
||||||
subscribedView
|
subscribedView
|
||||||
.frame(height: CGFloat(height))
|
.frame(height: CGFloat(height))
|
||||||
|
|||||||
@@ -146,12 +146,26 @@ struct SettingsView: View {
|
|||||||
private var subscriptionInfoView: some View {
|
private var subscriptionInfoView: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
theme.currentTheme.secondaryBGColor
|
theme.currentTheme.secondaryBGColor
|
||||||
PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: {
|
VStack {
|
||||||
Task {
|
PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: {
|
||||||
await
|
Task {
|
||||||
self.showManageSubscription()
|
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])
|
.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: .minute, value: -59, to: tmpDate)!
|
||||||
tmpDate = Calendar.current.date(byAdding: .second, value: -45, to: tmpDate)!
|
tmpDate = Calendar.current.date(byAdding: .second, value: -45, to: tmpDate)!
|
||||||
firstLaunchDate = tmpDate
|
firstLaunchDate = tmpDate
|
||||||
|
iapManager.updateEverything()
|
||||||
}, label: {
|
}, label: {
|
||||||
Text("Set first launch date back 29 days, 23 hrs, 45 seconds")
|
Text("Set first launch date back 29 days, 23 hrs, 45 seconds")
|
||||||
.foregroundColor(textColor)
|
.foregroundColor(textColor)
|
||||||
@@ -243,6 +258,7 @@ struct SettingsView: View {
|
|||||||
theme.currentTheme.secondaryBGColor
|
theme.currentTheme.secondaryBGColor
|
||||||
Button(action: {
|
Button(action: {
|
||||||
firstLaunchDate = Date()
|
firstLaunchDate = Date()
|
||||||
|
iapManager.updateEverything()
|
||||||
}, label: {
|
}, label: {
|
||||||
Text("Reset luanch date to current date")
|
Text("Reset luanch date to current date")
|
||||||
.foregroundColor(textColor)
|
.foregroundColor(textColor)
|
||||||
|
|||||||
@@ -115,6 +115,7 @@
|
|||||||
"purchase_view_current_subscription_expires_in" = "Trial expires in:";
|
"purchase_view_current_subscription_expires_in" = "Trial expires in:";
|
||||||
"purchase_view_current_subscription_expired_on" = "Trial expired on:";
|
"purchase_view_current_subscription_expired_on" = "Trial expired on:";
|
||||||
"purchase_view_loading" = "Loading subscription options";
|
"purchase_view_loading" = "Loading subscription options";
|
||||||
|
"purchase_view_restore" = "Restore";
|
||||||
|
|
||||||
"iap_warning_view_title" = "This view will no longer scroll in ";
|
"iap_warning_view_title" = "This view will no longer scroll in ";
|
||||||
"iap_warning_view_buy_button" = "Subscribe Now";
|
"iap_warning_view_buy_button" = "Subscribe Now";
|
||||||
|
|||||||
Reference in New Issue
Block a user