Pregunta

I need some advice about how to logically proceed to limit the use of an app, I mean, as Shazam does: you can use it only for some times during a month, then you have to wait until next month for use it again. I'm doing it with Xcode and objective c.

How can I understand if the month is changed?

¿Fue útil?

Solución

From a logical point of view, a basic method can be:

use a structure like:

struct run_time_for_month {
    int month;
    int minutes_left;
} 

and save in some option file (maybe with 0 as default).

when the application start, load the structure, then check the month. If it is 0, then is the first run, so set

month = current_month
minutes_left = 100 (for example)

and write it to the file.

If the month is greater than 0, then you use this code (I write some pseudo code here)

if current_month == saved_month then
    if minutes_left <= 0 then
         *** Running time for month ended ***
         *** Notify the user and exit the app ***
else
    saved_month = current_month
    minutes_left = 100

and save the file

Now, while the application is running, every x minutes (with x = 5 or 10) and when the application is quitting you use this code (again, pseudo code here)

minutes_left = minutes_left - x
if minutes_left <= 0 then
     *** Time for month ended ***
     *** Notify the user and exit the app ***

this a stripped down version of what I do in my code when I needed something like that, but again: I am not working with XCode and/or Objective C but with C++ so this can be only an idea.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top