Split Apple TV purchase (#467)

Full version features were listed when purchasing the Apple TV feature,
and this was very misleading.
This commit is contained in:
Davide De Rosa 2024-01-11 17:52:05 +01:00 committed by GitHub
parent 917e712510
commit 3fb521a584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 31 deletions

View File

@ -60,7 +60,7 @@ struct AddProviderView: View {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)
}.sheet(isPresented: $viewModel.isPaywallPresented) { }.sheet(isPresented: $viewModel.isPaywallPresented) {
NavigationView { NavigationView {
PaywallView(isPresented: $viewModel.isPaywallPresented) PaywallView(isPresented: $viewModel.isPaywallPresented, feature: .allProviders)
}.themeGlobal() }.themeGlobal()
}.navigationTitle(L10n.AddProfile.Shared.title) }.navigationTitle(L10n.AddProfile.Shared.title)
.themeSecondaryView() .themeSecondaryView()

View File

@ -54,8 +54,10 @@ extension PaywallView {
var body: some View { var body: some View {
List { List {
skFullVersion.map { if feature != .appleTV {
fullFeaturesSection(withHeader: $0.localizedTitle) skFullVersion.map {
fullFeaturesSection(withHeader: $0.localizedTitle)
}
} }
purchaseSection purchaseSection
.disabled(purchaseState != nil) .disabled(purchaseState != nil)

View File

@ -31,9 +31,9 @@ struct PaywallView: View {
@Binding private var isPresented: Bool @Binding private var isPresented: Bool
private let feature: LocalProduct? private let feature: LocalProduct
init<MT>(modalType: Binding<MT?>, feature: LocalProduct? = nil) { init<MT>(modalType: Binding<MT?>, feature: LocalProduct) {
let isPresented = Binding<Bool> { let isPresented = Binding<Bool> {
modalType.wrappedValue != nil modalType.wrappedValue != nil
} set: { } set: {
@ -44,7 +44,7 @@ struct PaywallView: View {
self.init(isPresented: isPresented, feature: feature) self.init(isPresented: isPresented, feature: feature)
} }
init(isPresented: Binding<Bool>, feature: LocalProduct? = nil) { init(isPresented: Binding<Bool>, feature: LocalProduct) {
productManager = .shared productManager = .shared
_isPresented = isPresented _isPresented = isPresented
self.feature = feature self.feature = feature

View File

@ -301,32 +301,35 @@ extension ProductManager {
// purchased platform -> may only purchase other platform // purchased platform -> may only purchase other platform
public func purchasableProducts(withFeature feature: LocalProduct?) -> [LocalProduct] { public func purchasableProducts(withFeature feature: LocalProduct?) -> [LocalProduct] {
var products: [LocalProduct] = {
if hasPurchased(.fullVersion) { // separate purchase
guard feature != .appleTV else {
if hasPurchased(.appleTV) {
return [] return []
} }
#if targetEnvironment(macCatalyst) return [.appleTV]
if hasPurchased(.fullVersion_macOS) {
return []
}
if hasPurchased(.fullVersion_iOS) {
return [.fullVersion_macOS]
}
return [.fullVersion, .fullVersion_macOS]
#else
if hasPurchased(.fullVersion_iOS) {
return []
}
if hasPurchased(.fullVersion_macOS) {
return [.fullVersion_iOS]
}
return [.fullVersion, .fullVersion_iOS]
#endif
}()
if feature == .appleTV && !hasPurchased(.appleTV) {
products.append(.appleTV)
} }
return products
if hasPurchased(.fullVersion) {
return []
}
#if targetEnvironment(macCatalyst)
if hasPurchased(.fullVersion_macOS) {
return []
}
if hasPurchased(.fullVersion_iOS) {
return [.fullVersion_macOS]
}
return [.fullVersion, .fullVersion_macOS]
#else
if hasPurchased(.fullVersion_iOS) {
return []
}
if hasPurchased(.fullVersion_macOS) {
return [.fullVersion_iOS]
}
return [.fullVersion, .fullVersion_iOS]
#endif
} }
} }

View File

@ -223,7 +223,7 @@ final class ProductManagerTests: XCTestCase {
reader.setReceipt(withBuild: 1500, products: []) reader.setReceipt(withBuild: 1500, products: [])
let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts) let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts)
XCTAssertTrue(sut.purchasableProducts(withFeature: .appleTV).contains(.appleTV)) XCTAssertEqual(sut.purchasableProducts(withFeature: .appleTV), [.appleTV])
} }
func test_givenAppleTV_whenDidPurchase_thenCannotPurchase() { func test_givenAppleTV_whenDidPurchase_thenCannotPurchase() {
@ -231,6 +231,6 @@ final class ProductManagerTests: XCTestCase {
reader.setReceipt(withBuild: 1500, products: [.appleTV]) reader.setReceipt(withBuild: 1500, products: [.appleTV])
let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts) let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts)
XCTAssertFalse(sut.purchasableProducts(withFeature: .appleTV).contains(.appleTV)) XCTAssertEqual(sut.purchasableProducts(withFeature: .appleTV), [])
} }
} }