mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-09 22:35:56 +05:45
* import Purchases -> import RevenueCat * updated Pod name to Purchases * updated more Pod names
83 lines
2.6 KiB
Swift
83 lines
2.6 KiB
Swift
//
|
|
// UserView.swift
|
|
// Magic Weather SwiftUI
|
|
//
|
|
// Created by Cody Kerns on 1/19/21.
|
|
//
|
|
|
|
import SwiftUI
|
|
import RevenueCat
|
|
|
|
/*
|
|
The app's user tab to display user's details like subscription status and ID's.
|
|
*/
|
|
|
|
struct UserView: View {
|
|
@ObservedObject var model = UserViewModel.shared
|
|
|
|
@State var newUserId: String = ""
|
|
|
|
var body: some View {
|
|
VStack {
|
|
/// - The user's current app user ID and subscription status
|
|
|
|
Text("Current User Identifier")
|
|
.font(.headline)
|
|
.padding(.bottom, 8.0)
|
|
.padding(.top, 16.0)
|
|
|
|
Text(Purchases.shared.appUserID)
|
|
|
|
Text("Subscription Status")
|
|
.font(.headline)
|
|
.padding([.top, .bottom], 8.0)
|
|
|
|
Text(model.subscriptionActive ? "Active" : "Not Active")
|
|
.foregroundColor(model.subscriptionActive ? .green : .red)
|
|
|
|
/// - Authentication UI
|
|
if !Purchases.shared.isAnonymous {
|
|
/// - If the user is not anonymous, we should give them the option to logout
|
|
|
|
Spacer()
|
|
|
|
Button("Logout") {
|
|
model.logout()
|
|
}
|
|
.foregroundColor(.red)
|
|
.font(.headline)
|
|
.frame(maxWidth: .infinity, minHeight: 64.0)
|
|
|
|
} else {
|
|
/// - If the user is anonymous, then give them the option to login
|
|
|
|
Text("Login")
|
|
.font(.headline)
|
|
.padding([.top], 24.0)
|
|
|
|
TextField("Enter App User ID", text: $newUserId) { (isEditing) in
|
|
|
|
} onCommit: {
|
|
guard !newUserId.isEmpty else { return }
|
|
|
|
model.login(userId: newUserId)
|
|
newUserId = ""
|
|
|
|
}.multilineTextAlignment(.center)
|
|
.padding(.top, 8.0)
|
|
|
|
Spacer()
|
|
}
|
|
|
|
/// - You should always give users the option to restore purchases to connect their purchase to their current app user ID
|
|
Button("Restore Purchases") {
|
|
Purchases.shared.restoreTransactions(nil)
|
|
}
|
|
.foregroundColor(.blue)
|
|
.font(.headline)
|
|
.frame(maxWidth: .infinity, minHeight: 64.0)
|
|
|
|
}.padding(.all, 16.0)
|
|
}
|
|
}
|