I have my app which requires a license to use properly, so when the app loads up I check to see if they have the license, if so they go to the main ContentView, if not you go to LockedView. I am using the Purchases framework to manage in the In App Purchases.
@main
struct RugbyAppApp: App {
@ObservedObject var userSettings = UserSettings.shared
var swiftUISpeech = SwiftUISpeech()
init(){
Purchases.debugLogsEnabled = true
Purchases.configure(withAPIKey: "UIGTHCnzIZUPvnxevAxUGTCchtpIpYZh")
userSettings.checkSubscription()
}
var body: some Scene {
WindowGroup {
if(userSettings.license == true){
ContentView().id(appState.gameID)
}
else{
LockedView()
}
}
}
}
Inside the initialiser I run userSettings.checkSubscription() which is this:
class UserSettings: ObservableObject {
static let shared = UserSettings()
@Published var license: Bool
init() {
//Other variables get initialised in here too
self.license = false
}
func checkSubscription(){
Purchases.shared.purchaserInfo { (info, error) in
if info?.entitlements["subscribed"]?.isActive == true{
self.license = true
}
else{
self.license = false
}
}
}
}
If the transaction is completed, and the Purchases frameworks receives the message saying everything has gone through I just update the license like this:
userSettings.license = true
I want the app to automatically refresh the screen when the license boolean (shown in the code above) gets updated. I thought using the @Published
property wrapper would do this, but I am needing to restart the app in order to see the change take place. Any ideas?