How to program events in ios?

I was tasked with writing an application that allows the user to send out emails for sending in the future.

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

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

Any pointers would be much appreciated.

+4
source share
6 answers

The first answer will technically allow you to set a timer that will fire every 2.5 seconds, however, the original poster asked for a solution that will fire at a specific time. To do this, you need to use the following NSTimer method:

- (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 indicate, but if this is an iOS application, it is important to understand that the timers scheduled to start at a distant date / time will not work if your application is not a priority application. It’s actually not possible to schedule such an event when your application is in the background on iOS, so you should consider this.

+7
source

Here is a snippet of code that sets one timer to call self imageSavedLabelOff: selector with itself (timer) as an object parameter for the method. The timer plans a call, which must be made in 2.5 seconds.

NSTimer *quickie = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(imageSavedLabelOff:) userInfo:nil repeats:NO];

+4
source

You may have already found the answer, but for future visitors like me, I would like to offer an answer, i.e. EventKit :

https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingEvents.html

You can plan / select events at any time and do your stuff accordingly. Hope this helps someone.

+1
source

You can achieve this using NSRunLoop. Check out the Thread Programming Guide .

0
source

In addition to using NSTimer, you should be aware that sending emails may end for several reasons (there is no network and others). Then you need to transfer the request, possibly refuse 3 repetitions and notify the user about this.

0
source

You can use -

 [self performSelector:@selector(myFunc:) withObject:nil afterDelay:5.0]; 
0
source

All Articles