mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
I added this in order to debug #2132. ### Changes: - Extracted `Core` framework to be used by both apps - Added new `watchOS` target - Changed `fastlane match` to also create profiles for this new target - Added a simple view in the watch app that displays a text if an entitlement is active, or a `restore` purchases button otherwise This is just a starting point, we can add more to it in the future. #### Note: _Unfortunately I haven't been able to test this because of an Apple bug (`FB11873951`):_ 
66 lines
1.6 KiB
Swift
66 lines
1.6 KiB
Swift
//
|
|
// ContentView.swift
|
|
// PurchaseTesterWatchOS Watch App
|
|
//
|
|
// Created by Nacho Soto on 12/12/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
import Core
|
|
import RevenueCat
|
|
|
|
struct ContentView: View {
|
|
|
|
let configuration: ConfiguredPurchases
|
|
|
|
@StateObject
|
|
private var revenueCatCustomerData = RevenueCatCustomerData()
|
|
|
|
var body: some View {
|
|
HomeView()
|
|
.environmentObject(self.revenueCatCustomerData)
|
|
.task {
|
|
for await customerInfo in self.configuration.purchases.customerInfoStream {
|
|
self.revenueCatCustomerData.customerInfo = customerInfo
|
|
self.revenueCatCustomerData.appUserID = self.configuration.purchases.appUserID
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
struct HomeView: View {
|
|
|
|
@EnvironmentObject
|
|
var revenueCatCustomerData: RevenueCatCustomerData
|
|
|
|
var body: some View {
|
|
if let customerInfo = self.revenueCatCustomerData.customerInfo,
|
|
!customerInfo.entitlements.active.isEmpty {
|
|
Text("Thanks for buying a subscription!")
|
|
} else {
|
|
Button {
|
|
Task<Void, Never> {
|
|
do {
|
|
_ = try await Purchases.shared.restorePurchases()
|
|
} catch {
|
|
print("Error: \(error)")
|
|
}
|
|
}
|
|
} label: {
|
|
Text("Restore purchases")
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final class RevenueCatCustomerData: ObservableObject {
|
|
|
|
@Published var appUserID: String? = nil
|
|
@Published var customerInfo: CustomerInfo? = nil
|
|
|
|
}
|