如何在ios中以编程方式安排事件? [英] How to schedule events programmatically in ios?

查看:100
本文介绍了如何在ios中以编程方式安排事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是编写一个应用程序,允许用户安排将来发送的电子邮件。

I have been tasked to write an app that allows a user to schedule emails to be sent out in future.

用户从日期选择器中选择日期时间,编写邮件和收件人,然后安排事件。发生日期/时间时,将发送消息。

The user selects a date time from a date picker, composes the message and recipient and then schedules the event. When the date/time occurs the message is sent out.

有人可以指导我如何进行调度,让我们说一条短信。我知道如何发送短信。只是不确定事情的安排方面。

Can someone guide me to how to get about scheduling lets say a text message. I know how to send a text message. Just was not sure on the scheduling aspect of things.

任何指针都会非常感激。

Any pointers will be much appreciated.

推荐答案

第一个响应在技术上允许你建立一个每2.5秒发射一次的计时器,但原始海报要求一个在特定时间点火的解决方案。为此你需要使用以下NSTimer方法:

The first response will technically allow you to establish a timer that will fire every 2.5 seconds, however the original poster asked for a solution that would fire at a specific time. For that you need to use the following method of NSTimer:

- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

第一个参数是 NSDate ,表示计时器应该何时触发。

The first argument is an NSDate indicating when the timer should fire.

原始海报没有指定,但如果这是一个iOS应用程序,那么重要的是要了解如果您的应用程序不是前台应用程序,计划在远程日期/时间触发的计时器将不会触发。实际上,当您的应用在iOS上的后台时,无法安排此类事件发生,因此您必须考虑到这一点。

The original poster did not specify, but if this is an iOS app then it is important to understand that timers scheduled to fire at a distant date/time will not fire if your app is not the foreground app. In fact there is no way to schedule such an event to occur when your app is in the background on iOS, so you must take that into account.

这篇关于如何在ios中以编程方式安排事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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