Advanced premium managing

This commit is contained in:
lumaa-dev 2024-09-23 18:30:45 +02:00
parent 049e6b9666
commit 8a691b5e07
7 changed files with 39 additions and 24 deletions

View File

@ -29,9 +29,11 @@ public class AppDelegate: NSObject, UIWindowSceneDelegate, Sendable, UIApplicati
}
}
let foundPremium = AppDelegate.hasPlus()
print("User has \(!foundPremium ? "no-" : "")access to Plus")
AppDelegate.hasPlus { subscribed in
print("User has \(!subscribed ? "no-" : "")access to Plus")
Self.premium = subscribed
}
windowWidth = window?.bounds.size.width ?? UIScreen.main.bounds.size.width
windowHeight = window?.bounds.size.height ?? UIScreen.main.bounds.size.height
Self.observedSceneDelegate.insert(self)
@ -51,23 +53,26 @@ public class AppDelegate: NSObject, UIWindowSceneDelegate, Sendable, UIApplicati
}
/// This function uses the REAL customer info to access the premium state
// static func hasPlus() -> Bool {
// #if DEBUG
// self.premium = true
// return true
// #else
// Purchases.shared.getCustomerInfo { (customerInfo, error) in
// self.premium = hasActuallyPlus(customerInfo: customerInfo)
// }
// return self.premium
// #endif
// }
static func hasPlus(completionHandler: @escaping (Bool) -> Void) {
#if targetEnvironment(simulator)
completionHandler(true)
#else
Purchases.shared.getCustomerInfo { (customerInfo, error) in
guard let error else {
let hasPrem: Bool = hasActuallyPlus(customerInfo: customerInfo)
completionHandler(hasPrem)
return
}
fatalError(error.localizedDescription)
}
#endif
}
/// This function returns a fake "true" value every time whatever the customer info is
static func hasPlus() -> Bool {
self.premium = true
return true
}
// static func hasPlus() -> Bool {
// self.premium = true
// return true
// }
private 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

View File

@ -13,9 +13,7 @@ struct BubbleApp: App {
#if DEBUG
Purchases.logLevel = .debug
#endif
if #available(iOS 18.0, *) {
Purchases.configure(withAPIKey: apiKey, appUserID: deviceId)
}
Purchases.configure(withAPIKey: apiKey, appUserID: deviceId)
}
BubbleShortcuts.updateAppShortcutParameters() //might not work?

View File

@ -17,6 +17,11 @@ struct Haptic: Hashable {
Haptic(intensity: 1.0, sharpness: 0.7, interval: 0.0),
Haptic(intensity: 1.0, sharpness: 0.3, interval: 0.2)
]
static let lock: [Haptic] = [
Haptic(intensity: 1.0, sharpness: 0.7, interval: 0.0),
Haptic(intensity: 0.55, sharpness: 0.55, interval: 0.1),
Haptic(intensity: 0.35, sharpness: 0.35, interval: 0.1)
]
}
class HapticManager {

View File

@ -575,7 +575,7 @@ struct PostingView: View {
//MARK: Post buttons
HStack(spacing: 18) {
actionMenu("plus.square.dashed") {
let addDisabled: Bool = self.drafts.count >= 3 && !AppDelegate.hasPlus()
let addDisabled: Bool = self.drafts.count >= 3 && !AppDelegate.premium
Button {
selectingDrafts.toggle()
@ -599,6 +599,7 @@ struct PostingView: View {
HapticManager.playHaptics(haptics: Haptic.success)
} else {
HapticManager.playHaptics(haptics: Haptic.lock)
UniversalNavigator.static.presentedSheet = .lockedFeature(.drafts)
}
} label: {

View File

@ -560,6 +560,9 @@ struct ProfileView: View {
.multilineTextAlignment(.leading)
Button {
let about: [Haptic] = Haptic.lock.reversed()
HapticManager.playHaptics(haptics: about)
uniNav.presentedSheet = .aboutSubclub
} label: {
Text("\(client?.server ?? "???")")

View File

@ -32,12 +32,12 @@ struct AboutView: View {
Toggle("setting.experimental.activate", isOn: $userPreferences.showExperimental)
.listRowThreaded()
.tint(Color(uiColor: UIColor.label))
.disabled(!AppDelegate.hasPlus())
.disabled(!AppDelegate.premium)
.onAppear {
do {
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.showExperimental = oldPreferences.showExperimental && AppDelegate.hasPlus()
userPreferences.showExperimental = oldPreferences.showExperimental && AppDelegate.premium
} catch {
print(error)
}

View File

@ -28,6 +28,7 @@ struct SettingsView: View {
if AppDelegate.premium || loggedAccounts.count < 3 {
uniNav.presentedSheet = .mastodonLogin(logged: $switched)
} else {
HapticManager.playHaptics(haptics: Haptic.lock)
uniNav.presentedSheet = .lockedFeature(.moreAccounts)
}
} label: {
@ -103,12 +104,14 @@ struct SettingsView: View {
}
.listRowThreaded()
#if !targetEnvironment(simulator)
Button {
openURL(URL(string: "https://apps.apple.com/app/id6477757490?action=write-review")!)
} label: {
Label("setting.review", systemImage: "star.fill")
}
.listRowThreaded()
#endif
Button {
navigator.navigate(to: .support)