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