Snooze method in EventKit Framework? - iphone

I am able to access all functionality of EKEventStore like save any event or remove any event from Calendar.
But how can create snooze for that event lets say 15 min snooze i needed for all saveEvent ?
I didn't find out as such method
Anyone know such method ?

If you are trying to set some function in your application to be performed after a fifteen second delay, you could use something like this:
[self performSelector:#selector(yourMethod) withObject:nil afterDelay:15];
EventKit is intended to set local notifications for the user that can be shown whether the user is running your application or not. They are exactly like push notifications, except they are stored locally on the user's device and don't require a network connection.
If you are are trying to add a snooze function to an EventKit notification, you could implement it in your application using the ApplicationDidLoadWithOptions method. That method is called whenever the user clicks the "OK" button on your local notification. As far as I know, there is no built in snooze functionality in the EventKit framework itself.

I've never tried that library, but have you tried NSTimer? Something like:
NSTimer *snoozeTimer;
//make it reachable in whole class
//setting the snooze timer. 900 s = 15 min. change to "repeats:NO" if you want just one snooze.
snoozeTimer = [NSTimer scheduledTimerWithTimeInterval:900.0 target:self selector:#selector(someAlarmMethod) userInfo:nil repeats:YES];
//and after finished snooze
[snoozeTimer invalidate];
Maybe it's not what you're looking for, but it might work :)

Related

Xcode iphone event listener

I need guidance for the following concept:
My iOS app has a text/messaging feature... I want to create a class that checks a database every 2 mins for new data no matter where the user is at in the application. I am assuming I would create a new class and just include it on all of my other files.
Is that the best workflow for what I am trying to achieve?
You can probably run a repeat NSTimer with defined frequency from your AppDelegate and in the implemented selector you can write your piece of code to check DB for new data and may be fire a notification if it finds new data. Then you can have any of your viewController listen to that notification to get their UI updated.
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(checkDBForUpdates) userInfo:nil repeats:YES];

iphone - how to send a sms message at a scheduled time

I am creating an application where user can send an SMS to the Recipient, and it is working fine. But I want to send Message at a scheduled time. For this I have two picker views, from one picker sender we can set date and from other sender can set time as I have shown in the attached screenshot.
How to trigger send button or send the sms at a scheduled time? Can I use an NSTimer?
Any help would be greatly appreciated. Thank you. If someone have any doubt related to question then let me know.
You can use NSTimer to schedule message.
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
here you can pass target as Your view controller that has sms sending functionality and selector will be your action method that gets called on sms button click.
But problem with NSTimer is that it stops when App is in background.If you have such requirement then NSTimer will not be useful.
You can use NSTimer in background also...
You need to make some changes in appDelegate...
Follow the below link to make your app wait for background task to complete
beginBackgroundTaskWithExpirationHandler
for long time in background try (more than 10 min)
How do I make my App run an NSTimer in the background?

How to stop timer when enter to background?

I have one timer that will countdown the time to 0. timer stop fine when it reach to 0 and when clicking submit button but timer doesn't stop when go out the application and come back.
I tried to create the timer in viewWillAppear and invalidate it in viewWillDisappear but timer still running after coming back from background. How to stop timer when enter to background? Any sample?
Thanks
You can use NSNotificationCenter. Add observer for UIApplicationDidEnterBackgroundNotification and stop your timer in it. You won't have to create your timer in AppDelegate in this case.
You can use the :
- (void)applicationDidEnterBackground:(UIApplication *)application
method of appDelegate class to stop your time . But for that you have to declare the timer inside the appDelegate class. Also you have to persist the counter when you will go to background .
Then you can use the viewWillAppear:
method to restart the timer.

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.
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.
Here's a snippet of code which sets a one use timer to call self's imageSavedLabelOff: selector with itself (the timer) as the object parameter to the method. The timer schedules the call to be made in 2.5 seconds.
NSTimer *quickie = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:#selector(imageSavedLabelOff:) userInfo:nil repeats:NO];
You may have already found the answer by now but for future visiters like me I would like to suggest an answer- i.e. EventKit :
https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingEvents.html
You can schedule/fetch events for any time and do your stuff accordingly. Hope this helps somebody.
You should be able to achieve this using NSRunLoop. Check out the Threading Programming Guide.
Apart from the use of NSTimer, you should be aware that sending of the E-Mail can fail for several reasons (no network available and others). Then you need to reschedule the request, maybe give up after 3 retries and notify the user about this.
You can use -
[self performSelector:#selector(myFunc:) withObject:nil afterDelay:5.0];

iPhone - Get user interaction event and automatic logout

In my iPhone app I want to logout the user if nothing happens till about 2 minutes (e.g. the user puts down the phone). Does anybody has such issue? What is the best way to implement this feature? I think I save the date of last event to NSUserDefaults, then on the next event first I check the current date. If the difference is larger than 2 minutes go to login screen, else refresh the stored date. But how can I get the touch event generally?
Thanks, madik
There's a method in UIApplicationDelegate for that:
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
Note that it also will be called when the app is going to background state. That will help you store the data whenever the app is going to inactive state. If you want to check if a certain amount of time has passed, you will have to use a NSTimer and store the last touch event. I think it cannot be done because you can't intercept all the touch events (Maybe it's over an object managed by the system. The status bar is an example). I guess is better to let the system to manage all the activity/inactivity stuff and store your data when necessary.
EDIT: I didn't understand what you mean the first time. Check this accepted answer, it accomplish what you need. Basically you have to subclass UIApplication and override sendEvent method.
'NSTimer'
When you say "how can I get the touch event generally?", if you mean how can you tell if the user is idle or not, you'll have to set up some system to gather all touch events at a higher level in your app. You could update the last touch time you mentioned in NSUserDefaults but that may be inefficient during the run of the app, so you could just post the touch event to your main app delegate and have it save the time of last touch. Which would also be where you could set up the 2 minute timer.
Something like:
- (void) someAppDelegateMethodThatYouCallForAnyUserEvent
{
[self.idleTimer invalidate];
self.lastEvent = [NSDate now];
self.idleTimer = [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:#selector(logoutAndGotoLogin) userInfo:nil repeats:NO];
...
}
You'll also have to do some cleanup in your app delegate methods when the app goes to background etc if you support that behavior.