-1

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.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Blade
  • 1,435
  • 1
  • 14
  • 22

1 Answers1

1

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
}
Jpellat
  • 907
  • 7
  • 29
  • Sounds good. But how would I be able to limit for example that he could only write five comments a day? Is the appraoch with the internal clock good or how would you do it? – Blade Aug 24 '12 at 15:58
  • For me have a timestamp of the last time you reset the counter to 0. Every time he do a commentary if the difference between the saved timestamp and the current time is 1 day or more you reset your counter. That seems good to you? That can be do on the singleton on the function that authorizes the user to do commentary – Jpellat Aug 24 '12 at 16:02
  • When you reset the counter you should reset the timestamp to – Jpellat Aug 24 '12 at 16:03
  • Yes, okay. Do you maybe have a sample or something to referr to? As of now I am a bit questioned on how to implement something like that :) – Blade Aug 24 '12 at 16:06
  • Hey. I am doing it likes this now: NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults]; int premium = [prefs integerForKey:@"premium"]; [prefs synchronize]; _timestamp=[[NSDate alloc] init]; _numberOfcomentary = premium; But I have to restart the app in order for it to update the NSUserDefaults in this ViewController. Do you have an idea, how I could it to differently? – Blade Aug 24 '12 at 18:16