如何在iPhone应用程序中每天的特定时间调用一个方法?
我想在我的 iPhone 应用程序中每天的特定时间调用一个方法。 我怎样才能实现这个目标?
I want to invoke a method daily at a specific time in my iPhone application.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 iPhone SDK 和封闭的应用程序并不能做很多事情。您可以让它在特定时间发送本地推送通知,但在用户手动打开您的应用程序之前不会执行您的代码。
请参阅最近提出的相关问题:是否可以让我关闭的应用程序在 iOS 中运行代码?
我见过的应用程序所做的一件事(例如闹钟应用程序等)就是让您的应用程序保持打开状态,然后让手机掉落睡着了,然后它仍然会在您想要的时候执行代码。但这只有在用户不点击主页按钮的情况下才有效。
There's not a whole lot you can do with the iPhone SDK and a closed app. You can have it send local push notifications at specific times, but that won't execute your code until the user manually opens your app.
See this related question recently asked: Is it possible to have my closed app run code in iOS?
One thing I've seen apps do (like alarm clock apps, etc) is have you leave your app open and just let the phone fall asleep and then it will still execute code when you want it to. But that only works as long as the user doesn't hit the home button.
安排本地通知。这就是大多数基本警报应用程序的工作原理。应用程序需要在方法执行时间之前运行以安排本地通知。安排本地通知后,可以关闭应用程序,并在特定时间调用该方法。
如果您配置了推送通知,那么您的应用程序根本不需要运行来安排该方法。这一切都可以从另一个应用程序完成。
在本地查看此文档以及来自 Apple 的推送通知。
Schedule a local notification. This is how most basic alarm apps work. The app needs to be running sometime before the method execution time to schedule a local notification. After the local notification has been scheduled, the app can be closed and the method will be invoked at the specific time.
If you have push notifications configured, then your app does not need to run at all to schedule the method. It can all be done from another application.
Check out this documentation on local and push notifications from Apple.
当应用程序未运行时,您无法在应用程序中运行特定代码。iOS 只允许在后台或应用程序退出时运行有限的功能。
you cannot run a specific code inside your application when its not running ..iOS allow only limited functionality to be run in background or when app is quit.