在我的iPhone应用程序中保存当前日期和时间? [英] saving current date and time in my iPhone application?

查看:105
本文介绍了在我的iPhone应用程序中保存当前日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用应用程序内购买来提供1年的订阅...。现在我需要保存用户购买订阅的时间和日期,并且需要检查何时订阅到期?我还没有使用过数据库之前是否有其他方法在我的应用程序中存储日期和时间并在每次应用程序启动时检索它?

In my application i am using In - App purchases to provide a subscription of 1 year….now i need to save the time and date when the user buys the subscription and need to check when the subscription expires?? i have not used database before is there any other way to store date and time in my application and retrieve it every time the application starts??

推荐答案

您只需将其存储在 NSUserDefaults 中:

[[NSUserDefaults standardUserDefaults] setObject:[NSDate now] forKey:@"purchaseDate"];

然后检索它:

NSDate *purchaseDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"purchaseDate"];

当你完成它之后:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"purchaseDate"];

这篇关于在我的iPhone应用程序中保存当前日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆