在app中设置iPhone日期/时间以进行测试? [英] Set iPhone date/time within app for testing purposes?

查看:164
本文介绍了在app中设置iPhone日期/时间以进行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有许多依赖于日期/时间的功能(例如如果日期是x,显示y)。我使用[NSDate日期]来获取用户的当前日期/时间。我可以测试功能通过手动更改我的iPhone上的日期/时间,但我想知道是否有一种方法以编程方式覆盖当前时间,以便我可以在模拟器中更快地进行测试。

I have a lot of functionality in my app that is date/time dependent (e.g. "if date is x, show y). I use [NSDate date] to get the current date/time of the user. I can test functionality by manually changing the date/time on my iPhone but I'm wondering if there is a way to programatically overwrite the the current time so I can test in the simulator and more quickly.

推荐答案

您可以使用您想要的任何日期/时间创建NSDate对象。只需通过方法运行代码即可获得当前时间,并在此方法中返回实际日期用于生产或您选择进行测试的日期。

You can create NSDate objects with any date/time you want. Just run your code through a method to get "the current" time and inside this method either return the real date for production or some date of your choice for testing.

这篇关于在app中设置iPhone日期/时间以进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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