Limit database entries for free version
I'm looking to offer a free version of my app. The limitation would be that once you save 15 notes to the database, you will be limited to adding 5 notes per month. Every time you reach the limit and every time you attempt to make a new n开发者_StackOverflow社区ote after the limit has been reached, I will prompt the user to unlock the app via in-app purchase. 30 days after the initial limit has been reached, or the first of the month if it's easier, they'll be able to add 5 notes and I won't bother them until they use them all. The limits won't rollover.
Does anyone have ideas on the best way to tackle this?
I suggest you take a look at the Wrapper (also called Adapter) Design Pattern. A solution implementing that pattern would include:
- A class whose purpose is to add a Note to the database. Let's call the method addNote(Note newNote)
class NotesManagement { public boolean addNote(Note newNote) { //Add Note to database and return whether it was successfull or not } }
- A class that wraps the previous class and overrides that method:
class TrialNotesManagement extends NotesManagement { private NotesManagement notesManagement; public TrialNotesManagement() { notesManagement = new NotesManagement(); } @Override public boolean addNote(Note newNote) { if (isAllowedToAdd()) { return notesManagement.add(newNote); } else { return false; } } private boolean isAllowedToAdd() { //Do the check--Suggestion: in the "database" have a counter that it's reseted each 1st daty of the month } }
- The class that handle the requests should look like this:
class AppController { NotesManagement notesManagement; public AppController() { if (isTrial()) { notesManagement = new TrialNotesManagement(); } else { notesManagement = new NotesManagement(); } } public boolean addNote(Note newNote) { notesManagement.addNote(newNote); } }
I'd highly recommend using web communication to accomplish this, even if your app doesn't use the internet otherwise. If you really want to be able to trust that the user doesn't tamper with parameter to eke out extra free uses, you should do the verification on your own server, not their device.
Whenever a note is created, a message should be sent to your server with a user identifier. You can then keep track of the notes (even if you don't store the content of the notes), and send a message back when it's time to prevent the note from being created.
This way, you can also change the threshold if you have to without changing your app.
精彩评论