Mercurial > public > simoleon
comparison Simoleon/Helpers/RestoreButton.swift @ 28:4f862c618b44
Implemented RevenueCat
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 22 Jul 2021 19:06:01 +0100 |
parents | |
children | c52966834f83 |
comparison
equal
deleted
inserted
replaced
27:d95582268b44 | 28:4f862c618b44 |
---|---|
1 // | |
2 // RestoreButton.swift | |
3 // Simoleon | |
4 // | |
5 // Created by Dennis Concepción Martín on 22/07/2021. | |
6 // | |
7 | |
8 import SwiftUI | |
9 import Purchases | |
10 | |
11 struct RestoreButton: View { | |
12 @Binding var showingSubscriptionPaywall: Bool | |
13 @EnvironmentObject var subscriptionController: SubscriptionController | |
14 | |
15 @State private var restoringPurchases = false | |
16 @State private var alertTitle = "" | |
17 @State private var alertMessage = "" | |
18 @State private var showingAlert = false | |
19 | |
20 var body: some View { | |
21 Button(action: restorePurchases) { | |
22 if restoringPurchases { | |
23 ProgressView() | |
24 } else { | |
25 Text("Restore purchases") | |
26 } | |
27 } | |
28 .alert(isPresented: $showingAlert) { | |
29 Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) | |
30 } | |
31 } | |
32 | |
33 private func restorePurchases() { | |
34 restoringPurchases = true | |
35 | |
36 Purchases.shared.restoreTransactions { purchaserInfo, error in | |
37 if purchaserInfo?.entitlements["all"]?.isActive == true { | |
38 subscriptionController.isActive = true | |
39 showingSubscriptionPaywall = false | |
40 } else { | |
41 alertTitle = "No subscriptions found" | |
42 alertMessage = "You are not subscripted to Simoleon yet." | |
43 restoringPurchases = false | |
44 showingAlert = true | |
45 } | |
46 | |
47 if let error = error as NSError? { | |
48 alertTitle = error.localizedDescription | |
49 alertMessage = error.localizedFailureReason ?? "If the problem persists send an email to dmartin@dennistech.io" | |
50 showingAlert = true | |
51 } | |
52 } | |
53 } | |
54 } | |
55 | |
56 struct RestoreButton_Previews: PreviewProvider { | |
57 static var previews: some View { | |
58 RestoreButton(showingSubscriptionPaywall: .constant(true)) | |
59 } | |
60 } |