Solved

How do I use XML data to populate iOS calendar?

Posted on 2014-02-14
2
497 Views
Last Modified: 2014-05-22
I am adding calendar appointments to the native iOS calendar by retrieving XML data from a database.  The XML data is similar to this.
<draw>
<date>2014-02-11</date>
<starttime>08:00:00</startttime>
<endtime>12:00:00</endtime>
<street>509 NORTH 44TH</street>
</draw>
<draw>
<date>2014-02-11</date>
<starttime>16:00:00</startttime>
<endtime>18:00:00</endtime>
<street>4107 BLOSSUMWOOD DR</street>
</draw>

I am wanting to use the date, start time and end time to set the appointment and use the address as the title.

My Xcode looks like this. I have commented the sections I need populated from XML.
-(IBAction)saveEvent:(id)sender

{
    today = [NSDate date];
    messageDate = date;
    store=[[EKEventStore alloc] init];
    EKEvent *addEvent=[EKEvent eventWithEventStore:store];
    addEvent.title=@"1202 Test Way";//needs to be street from XML.
    addEvent.startDate=today;//needs to be date and starttime from XML.
    addEvent.endDate=today;//needs to be date and endtime from XML.
    [addEvent setCalendar:[store defaultCalendarForNewEvents]];
    addEvent.alarms=[NSArray arrayWithObject:[EKAlarm    alarmWithAbsoluteDate:addEvent.startDate]];
    [store saveEvent:addEvent span:EKSpanThisEvent error:nil];
   
   
}
0
Comment
Question by:aduvall
2 Comments
 
LVL 20

Accepted Solution

by:
darbid73 earned 500 total points
ID: 40074316
Unless I am mistaken your issue is converting your XML date and times to something you can use for the EventStore.

Thus you need to convert a date/time string into a NSDate.  Once you know this there are many examples.

This is but one example.

Here is more less specific Apple Developer information on what you need to do.

The one thing I am missing from your xml is what time this is? To create a NSDate you are going to need to tell iOS where the time comes from, is the XML based on the users local time or is the XML based on for example GMT.  This will be needed otherwise you will get strange results.
0
 

Author Comment

by:aduvall
ID: 40083267
Thank you the example solved my question.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question