Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule events programmatically in 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.

like image 373
jini Avatar asked Oct 10 '11 16:10

jini


1 Answers

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

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

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.

like image 165
Carter Avatar answered Nov 14 '22 21:11

Carter