saving current date and time in my iPhone application?

不羁的心 提交于 2019-12-31 03:35:21

问题


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??


回答1:


You can simply store it in NSUserDefaults:

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

Then retrieve it like such:

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

And when you're done with it:

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



回答2:


You should store the purchase of a subscription on a server, with backup in place, not only on the device.

You might have noticed that if you delete any iPhone app, and later re-install it, then the next download is free. There can be many reasons as to why the user might loose your app, a system update went bad, or whatever.

Apple specifically requires that the user do not loose what they have bought. If you have promised 1 year, then you must make sure they get 1 year no matter what happens to your app. Otherwise Apple can, and will, reject your app.

Storing the expiration date on a server also give the added benefit of protection against users fiddling with your data and granting themselves extended subscriptions.

Start by looking at the In App Purchase Programming Guide.



来源:https://stackoverflow.com/questions/4201623/saving-current-date-and-time-in-my-iphone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!