Files
purchases-ios/Tests/TestingApps/PurchaseTesterSwiftUI/PurchaseTesterWatchOS/ContentView.swift
T
NachoSoto 432b704dc7 Purchase Tester: added companion watchOS app (#2140)
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`):_


![incoming-722CC7FA-D970-4E23-AB88-50167248D98D](https://user-images.githubusercontent.com/685609/207672762-23abe3e7-6052-4b16-bdf2-7b1e502ffd81.PNG)
2022-12-21 07:31:58 -08:00

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
}