我有一个允许用户兑换优惠券代码的应用程序,但是我想限制它,以便他们每 30 分钟只能领取一个。
因此,我不知何故需要存储他们上次兑换优惠券的时间,如果他们尝试兑换另一张优惠券,该应用程序会检查最后一次,如果最后一张是半小时前,则只会给他们一张新优惠券。
我会将数据存储在用户首选项中还是有更好的方法?
Storing a timestamp of when the last voucher was redeemed in NSUserDefaults
is probably fine for a simple solution.
But how secure do you need this to be? As a general rule, and especially if this needs to be strictly enforced for financial reasons, never trust the client. Meaning that you should have a server to verify the codes, and enforce usage restrictions.