mirror of
https://github.com/lumaa-dev/BubbleApp.git
synced 2024-12-26 16:55:15 +01:00
Better handling ShopView
This commit is contained in:
parent
6a26970e37
commit
738d90f27f
@ -1129,7 +1129,7 @@
|
||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||
CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = BubbleWidgets/Info.plist;
|
||||
@ -1164,7 +1164,7 @@
|
||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||
CODE_SIGN_ENTITLEMENTS = BubbleWidgets/BubbleWidgetsExtension.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = BubbleWidgets/Info.plist;
|
||||
@ -1327,7 +1327,7 @@
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_ASSET_PATHS = "";
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
ENABLE_MODULE_VERIFIER = NO;
|
||||
@ -1370,7 +1370,7 @@
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Bubble/Bubble.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_ASSET_PATHS = "";
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
ENABLE_MODULE_VERIFIER = NO;
|
||||
@ -1407,7 +1407,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = AuthService/Info.plist;
|
||||
@ -1437,7 +1437,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
CURRENT_PROJECT_VERSION = 307;
|
||||
DEVELOPMENT_TEAM = HB5P3BML86;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = AuthService/Info.plist;
|
||||
|
@ -13,9 +13,7 @@ public struct ShopView: View {
|
||||
@State private var purchaseError: Bool = false
|
||||
@State private var hasSub: Bool = false
|
||||
|
||||
private var canPay: Bool {
|
||||
return true
|
||||
}
|
||||
@State private var canPay: Bool = true
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
@ -59,7 +57,7 @@ public struct ShopView: View {
|
||||
|
||||
Button {
|
||||
// showLifetime.toggle()
|
||||
purchase(entitlement: .lifetime)
|
||||
PremiumFeature.purchase(entitlement: .lifetime)
|
||||
} label: {
|
||||
Text("shop.bubble-plus.lifetime")
|
||||
}
|
||||
@ -115,6 +113,13 @@ public struct ShopView: View {
|
||||
}
|
||||
}
|
||||
.task {
|
||||
Purchases.shared.getOfferings { offerings, err in
|
||||
if let err {
|
||||
self.canPay = false
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
AppDelegate.hasPlus { subscribed in
|
||||
self.hasSub = subscribed
|
||||
}
|
||||
@ -271,7 +276,7 @@ extension ShopView {
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
purchase(entitlement: selectedPlan.getEntitlement())
|
||||
PremiumFeature.purchase(entitlement: selectedPlan.getEntitlement())
|
||||
} label: {
|
||||
Text("shop.bubble-plus.subscribe")
|
||||
}
|
||||
@ -425,6 +430,26 @@ extension ShopView {
|
||||
self.description = description
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user