Question

I've been developing a calendar app for iOS which is bugging me with lots of issues.

I'm using local notifications for reminders. What is the best way to store event dates, alarm dates or whatever? I mean, the issues were coming up caused by timezone differences etc. I'm storing events in Core Data. I've been using NSDate for date storage but i'm not sure it's a good way to query and represent events in a calendar view. Because of timezone, the events were showing up at wrong days (like 1 day before from real day).

Also, is there a tutorial or open source project that I can peek into? I haven't encountered anything comprehensive, only little tutorials on how to use tapku calendar view.

Edit: I'm not asking a question about only calendar views. I'm asking about infrastructure of calendar app.

Was it helpful?

Solution

You should store with NSDate, and present with NSDateComponents.

Because of timezone, the events were showing up at wrong days (like 1 day before from real day).

This happens because NSDate is an absolute point in time. You need to do the proper conversions to display based on the users locale. The NSDateComponents (along with NSCalendar) will take care of this.

The Date and Time Programming Guide will tell you all that you need to know, but the first paragraph sets the tone:

There are three main classes used for working with dates and times.

  • NSDate allows you to represent an absolute point in time.
  • NSCalendar allows you to represent a particular calendar, such as a Gregorian or Hebrew calendar. It provides the interface for most date-based calculations and allows you to convert between NSDate objects and NSDateComponents objects.
  • NSDateComponents allows you to represent the components of a particular date, such as hour, minute, day, year, and so on.

OTHER TIPS

You can refer/use the following frameworks which are available on Github

  1. TapkuLibrary
  2. Kal
  3. ios-calendar with tutorial to configure.
  4. GCCalendar

to get your calendar-app working.

Hope this helps

I think you can store the timestamp value of the date

[[NSDate date] timeIntervalSince1970];

And i did not get the idea why you will get wrong day when you store as the NSDate value. Any more information about that?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top