Better handling ShopView

This commit is contained in:
lumaa-dev 2024-09-27 15:07:12 +02:00
parent 6a26970e37
commit 738d90f27f
2 changed files with 36 additions and 31 deletions

View File

@ -1129,7 +1129,7 @@
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements; CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BubbleWidgets/Info.plist; INFOPLIST_FILE = BubbleWidgets/Info.plist;
@ -1164,7 +1164,7 @@
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements; CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BubbleWidgets/Info.plist; INFOPLIST_FILE = BubbleWidgets/Info.plist;
@ -1327,7 +1327,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements; CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
ENABLE_MODULE_VERIFIER = NO; ENABLE_MODULE_VERIFIER = NO;
@ -1370,7 +1370,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements; CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
ENABLE_MODULE_VERIFIER = NO; ENABLE_MODULE_VERIFIER = NO;
@ -1407,7 +1407,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AuthService/Info.plist; INFOPLIST_FILE = AuthService/Info.plist;
@ -1437,7 +1437,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 305; CURRENT_PROJECT_VERSION = 307;
DEVELOPMENT_TEAM = HB5P3BML86; DEVELOPMENT_TEAM = HB5P3BML86;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AuthService/Info.plist; INFOPLIST_FILE = AuthService/Info.plist;

View File

@ -13,9 +13,7 @@ public struct ShopView: View {
@State private var purchaseError: Bool = false @State private var purchaseError: Bool = false
@State private var hasSub: Bool = false @State private var hasSub: Bool = false
private var canPay: Bool { @State private var canPay: Bool = true
return true
}
public var body: some View { public var body: some View {
VStack { VStack {
@ -59,7 +57,7 @@ public struct ShopView: View {
Button { Button {
// showLifetime.toggle() // showLifetime.toggle()
purchase(entitlement: .lifetime) PremiumFeature.purchase(entitlement: .lifetime)
} label: { } label: {
Text("shop.bubble-plus.lifetime") Text("shop.bubble-plus.lifetime")
} }
@ -115,6 +113,13 @@ public struct ShopView: View {
} }
} }
.task { .task {
Purchases.shared.getOfferings { offerings, err in
if let err {
self.canPay = false
dismiss()
}
}
AppDelegate.hasPlus { subscribed in AppDelegate.hasPlus { subscribed in
self.hasSub = subscribed self.hasSub = subscribed
} }
@ -271,7 +276,7 @@ extension ShopView {
Spacer() Spacer()
Button { Button {
purchase(entitlement: selectedPlan.getEntitlement()) PremiumFeature.purchase(entitlement: selectedPlan.getEntitlement())
} label: { } label: {
Text("shop.bubble-plus.subscribe") Text("shop.bubble-plus.subscribe")
} }
@ -425,6 +430,26 @@ extension ShopView {
self.description = description self.description = description
self.systemImage = systemImage self.systemImage = systemImage
} }
static func hasActuallyPlus(customerInfo: CustomerInfo?) -> Bool {
return customerInfo?.entitlements[PlusEntitlements.lifetime.getEntitlementId()]?.isActive == true || customerInfo?.entitlements[PlusEntitlements.monthly.getEntitlementId()]?.isActive == true || customerInfo?.entitlements[PlusEntitlements.yearly.getEntitlementId()]?.isActive == true
}
static func purchase(entitlement: PlusEntitlements) {
Purchases.shared.getOfferings { (offerings, error) in
if let product = entitlement.toPackage(offerings: offerings) {
Purchases.shared.purchase(package: product) { (transaction, customerInfo, error, userCancelled) in
if hasActuallyPlus(customerInfo: customerInfo) {
print("BOUGHT PLUS")
AppDelegate.premium = true
}
}
}
if let e = error {
print(e)
}
}
}
} }
} }
@ -466,23 +491,3 @@ enum PlusEntitlements: String {
} }
} }
} }
private func hasActuallyPlus(customerInfo: CustomerInfo?) -> Bool {
return customerInfo?.entitlements[PlusEntitlements.lifetime.getEntitlementId()]?.isActive == true || customerInfo?.entitlements[PlusEntitlements.monthly.getEntitlementId()]?.isActive == true || customerInfo?.entitlements[PlusEntitlements.yearly.getEntitlementId()]?.isActive == true
}
private func purchase(entitlement: PlusEntitlements) {
Purchases.shared.getOfferings { (offerings, error) in
if let product = entitlement.toPackage(offerings: offerings) {
Purchases.shared.purchase(package: product) { (transaction, customerInfo, error, userCancelled) in
if hasActuallyPlus(customerInfo: customerInfo) {
print("BOUGHT PLUS")
AppDelegate.premium = true
}
}
}
if let e = error {
print(e)
}
}
}