Hello,
I'm currently developing a SwiftUI app for macOS that includes both free and premium features. One of the features is the maximum amount of items that can be stored in the app: the free version allows users to store up to 10 items, whereas premium users can store up to 1000.
The issue I'm facing is with securing the premium feature. I'm using UserDefaults
to store the value of the feature, with a key named maxStorageSize
. The user can configure this using a dropdown (there are also other options between 10 and 1000). For non-premium users, this dropdown is disabled and set to a default of 10. For premium users, the dropdown is enabled and thus the user can change the setting to a higher value.
However, I've realised that this limitation can be bypassed by using the defaults
CLI tool to change the value of maxStorageSize
underneath the application's knowledge, effectively circumventing the premium requirement.
My current workaround is:
- check the user defaults on launch and if the user is non-premium and any of the premium features have been changed: reset them.
- continuously monitor for updates on the defaults and if the user is non-premium and a premium feature value has been changed: reset it.
This seems to work but feels a little hacky. I'm wondering what mechanisms you've come up with to solve this.