How to include restrictions inside an free/premium app?
-
28-06-2021 - |
Pregunta
I was wondering how it is possible, to include certain restrictions inside an app, when the user loaded the free version of it. For example: I have a tableView with around 100 entries. The user can favorite 10 of those, but not more, unless the user buys the premium version! I was thinking of just putting "return 10" in the numberOfRowsInSection on the FavoritetableViewController. Or is there a better/comfortabler way to do this?
There is also a commentary function. So if the user sees a comment, he/she wants to reply to, he/she only has to click on "answer". But for free users I wanna limit that interaction by 5. So they can write 5 comments a day. I was playing with the thought of implementing some sort of internal clock. And everytime the user clicks on "Submit" a counter goes up. And when the counter reaches 5, the button gets disabled. And after the clock has past 24 hours this count gets resetted. But to be honest I don't know how to do that yet. So any idea or input would be greatly appreciated.
Solución
I don't know if it's the best solution and if will help you. For me the way to do that is have a singleton class. You should initialize him at the app launching with a Bool var premium. At this moment you should initialize the class with all the data you need: number of favorite lines, comments the last day, ....
Before every "premium operation", you should acces to a method like: BOOL authorized = [[AuthorizeSingleton sharedmanager] operation]
. Here you will have all the test needed to know if he can perform the premium action.
You should acces to this singleton from a viewController every time someones wants to do a premium action. If the return is NO you pop a error message, in the other case you do the action.
If the user is premium always return yes.
Coded quickly something like that
Here the .h
#import <Foundation/Foundation.h>
@interface AuthorizeSingleton : NSObject
@property (strong, nonatomic) NSNumber* premium;
@end
Here the .m #import AuthorizedSingleton.h
AuthorizeSingleton* _sharedInstance=nil;
@interface AuthorizeSingleton ()
@property (strong, nonatomic) NSDate* timestamp;
@property (strong, nonatomic) NSNumber* numberOfcomentary;
@end
@implementation AuthorizeSingleton
@synthesize timestamp=_timestamp, numberOfcomentary=_numberOfcomentary;
-(id)init{
if (self == [super init]) {
//Here you should take data from your persistence(NSUSerDefaults or something like that) Here I initialize at 0
_timestamp=[[NSDate alloc] init];
_numberOfcomentary= [NSNumber numberWithInt:0];
}
return self;
}
+(AuthorizeSingleton*)sharedInstance{
if (!_sharedInstance) {
_sharedInstance = [[AuthorizeSingleton alloc] init];
}
return _sharedInstance;
}
-(BOOL)shouldDoComentary{
NSDate* today= [[NSDate alloc] init];
NSTimeInterval interval = [_timestamp timeIntervalSinceDate: today];
if (interval>60*60*24) {
_timestamp=today;
_numberOfcomentary= [NSNumber numberWithInt:0];
}
if (_numberOfcomentary.integerValue>5 && !_premium.boolValue) {
return NO;
}
return YES;
}
@end
I don't test it but that's the idea. You call the class from where you want an authorization like
BOOL auth = [[AuthorizedSingleton sharedInstance] shouldDoComentary]
if(!auth){
//show error
}
else{
//do action
}