如何限制一个月内应用程序的使用

发布于 2025-01-04 04:35:11 字数 141 浏览 1 评论 0原文

我需要一些关于如何从逻辑上限制应用程序使用的建议,我的意思是,就像 Shazam 所做的那样:您在一个月内只能使用它几次,然后您必须等到下个月才能再次使用它。我正在使用 Xcode 和 Objective C 来完成它。

如果月份改变了,我该如何理解?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2025-01-11 04:35:11

从逻辑的角度来看,基本方法可以是:

使用如下结构:

struct run_time_for_month {
    int month;
    int minutes_left;
} 

并保存在某个选项文件中(可能默认为 0)。

当应用程序启动时,加载结构,然后检查月份。如果为0,则为第一次运行,因此设置

month = current_month
minutes_left = 100 (for example)

并写入文件。

如果月份大于 0,则使用此代码(我在这里编写一些伪代码)

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

并保存文件

现在,当应用程序运行时,每 x 分钟(x = 5 或 10)以及当应用程序退出时你使用这段代码(再次,这里是伪代码),

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

这是当我需要类似的东西时我在代码中所做的精简版本,但同样:我不是使用 XCode 和/或 Objective C,而是使用 C++,所以这可以只是一个想法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文