Fetching Date of upcoming specified days - iphone

I want to schedule UILocal Notifications and want them to be repeated on particular days specified by the user.The user specifies a particular date and then specifies the days on which he wants to repeat the same notification.
How do i fetch the dates from the specified days after user selection.I know i will have to fire multiple local notifications for that purpose.
Please help
Thanks,
Aditya

Unfortunately the creation of a UILocalNotification object only provides the option to recur on a single calendar unit. For example, you can have a notification that repeats every hour, or every day, or every weekday, etc. There is no way without a little effort to create a notification that repeats every Tuesday and Thursday.
That having been said: you can provide each UILocalNotification with a custom NSDictionary, assigned to the userInfo property on the object. If I were you, I would create a custom structure that contains a little bit more information about the notification, and store it in the dictionary. If you wanted it to be simple, it could just be a class containing 7 booleans, one for each day of the week.
As an example, you could create a UILocalNotification that repeats daily, with the above structure whose boolean values for Tuesday and Thursday are YES, and all other days are NO.
When your local notification fires, and you respond to it via the method:
-(void)application:(UIApplication *)application didReceiveLocationNotification:(UILocationNotification *)notification
You can retrieve this userInfo dictionary from the notification, take a closer look at the underlying repeat, and ignore the notification if the boolean value for the current day is NO.

Related

Editing recurring events in Calendar

When editing recurring events in Calendar, if the event time is changed, should the recur break events that have been edited previously be removed or maintained?
I'm assuming that you are talking about changing the event time for "all" instances.
The iCalendar specification does not mandate anything with regards to such a scenario. A common practice though is to have the client split the recurring event into 2:
* the existing recurring event is bounded by adding an UNTIL date in the RRULE. The UNTIL value corresponds to the last instance before the change of time. All instances that had been edited in that time period are preserved.
* a new event (with a new UID etc...) gets created, with a DTSTART corresponding to the new time. Edited instances (exceptions) for that time period are removed.
Both events are linked together via a cross referencing RELATED-TO property.

iCal rrule for two different lengths

I want to enter an event in my calendar that runs on Monday and Tuesdays from 8-3 and Saturdays from 8-12 every week. My app is supporting rrule's. Is it possible to pack that into a single rrule?
If it would be only the weekdays, then the rule would be simple and do look like:
FREQ=WEEKLY;BYDAY=MO,TU
Any hints are appreciated.
The duration of the event is not part of the rrule definition but is rather determined by the DTSTART/DTEND or DTSTART/DURATION combinations so there is no way to have one single event representing what you want (unless you create exceptions for every single instances on Saturday)
The best you can do is to use the RELATED-TO property (https://www.rfc-editor.org/rfc/rfc5545#section-3.8.4.5) to link the 2 events.

How to find the date healthkit began receiving input with Swift

I have a function that takes the step data for every day until a point, which is yet to be determined. What I need is a way to determine the day that HealthKit began receiving step count input. I tried to have it repeat until it detects 3 days of zero activity, but that seems too unspecific. Is there an object for the start date?
I don't think that there is an object for the start date readily available, as far as I know.
One solution could be to pull all the data using a HKStatisticsCollectionQuery by day without any predicate ordered by the date, and the first date in the results should be the start date.
Hope this helps.

Is Trigger scheduled to fire at a specific time?

How can we know if a trigger is scheduled to fire at a specific time? i searched through all the apis but couldnt find. The closest api I found is getNextFireTime() and getFireTimeAfter(Date afterTime). My requirement is to find that if a trigger is scheduled to fire at a specific time.. If not schedule it to fire at that time.
You could use the Quartz TriggerUtils utility methods.
The method computeFireTimes(org.quartz.spi.OperableTrigger trigg, Calendar cal, int numTimes) returns a list of Dates that are the next fire times of a Trigger.
The method computeFireTimesBetween(org.quartz.spi.OperableTrigger trigg, Calendar cal, java.util.Date from, java.util.Date to) returns a list of Dates that are the next fire times of a Trigger that fall within the given date range.
I hope this helps.

Speed up fetch of EKEvents

in my app I'm displaying a list of EKEvents and I would like to display all events of a month in a UITableView, each section containing the respective days. Well, this works and I get all the data, I need, but the fetch is very slow.
The problem consists in events, which spread across multiple days.
Let's say I'm going on vacation from 10th of November until 17th of November.
My search predicate has a startDate with 1st of November and an endDate with 30th of November.
I do an enumerateEventsMatchingPredicate or eventsMatchingPredicate, whatever, both are slow.
I get an array in return with all events taking place in November, as well as my vacation.
But my vacation is just one EKEvent object. So if I want to display a monthly list view of events it would only appear once, on 10th of November, but for reasons of clarity I would to show it on every day it takes place, 10th, 11th, ... 17th.
So what I do is, iterate over each day in a month and do a fetch :-/ This way I get the correct amount of events that take place on a specific day, but ... it feels so complicated.
I already put the fetch into a dispatch_async, so the fetch doesn't block the UI and after the fetch is finished the tableView gets reloaded and cells redrawn. But it still takes time. No userfriendly time.
How do you perform those searches? Do you have any tips on how to speed up the search, maybe a little code snippet or can point me in the right direction!?
Is my question clear? :-/
Thanks,
-Martin.
Fetches are slow especially if there is a lot of recurring events. What I did in my app, is to fetch only once, and parse whole-day-multiple-spanning-day-events to chunks. I abstracted events: I create "date" class, which has NSString properties usable as section titles in table view, and one of its ivars is array with matching "events". "events" are not EKEvents, but my class, to which I copy needed properties from EKEvents. From multiple day spanning single whole day EKEvent I create corresponding "events". Parsing is quite quick - the slowdown is when getting properties from fetched recurring EKEvents.