Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-17-2010, 01:21 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 11
bgp1 is on a distinguished road
Default Add event to iPhone / iPad iCal

Hello,

I have an application I am developing that pulls events from an RSS feed and then displays events to the user. I want to add the ability for the user to add the event they are looking at to the calendar on the iPhone but I have been unsuccessful in finding sample code or an example that does this. Does anyone have any sample code or anything that can help me accomplish this?

I am still just learning Cocoa (been at it for about 4 months) but I am very skilled in other C-based languages.


Thank you very much in advance!
bgp1 is offline   Reply With Quote
Old 11-19-2010, 08:19 AM   #2 (permalink)
57Digital Ltd, Mobile Dev
iPhone Dev SDK Supporter
 
iPhoneConnection's Avatar
 
Join Date: Apr 2010
Location: Sheffield
Posts: 144
iPhoneConnection is on a distinguished road
Default

You can only access the calendar as of iOS 4.0, see here: Event Kit Framework Reference
iPhoneConnection is offline   Reply With Quote
Old 11-19-2010, 08:52 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 11
bgp1 is on a distinguished road
Default

Thanks for the reply! Coding to iOS 4 standards shouldn't be an issue. Here's a copy of the code I have in my button on my interface. Would this work? I realized there isn't a way to test this on the simulator because the iCal doesn't exist there. I'd have to test it on the device...which is a hassle.

Code:
- (IBAction) addEvent {
	NSLog(@"button clicked");
	EKEventStore *eventStore = [[EKEventStore alloc] init];
	
    EKEvent *eventToAdd  = [EKEvent eventWithEventStore:eventStore];
    eventToAdd.title     = event.title;
	
    eventToAdd.startDate = [[NSDate alloc] init];
    eventToAdd.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:eventToAdd.startDate];
	
    [eventToAdd setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *err;
    [eventStore saveEvent:eventToAdd span:EKSpanThisEvent error:&err];
}
bgp1 is offline   Reply With Quote
Old 11-19-2010, 08:57 AM   #4 (permalink)
57Digital Ltd, Mobile Dev
iPhone Dev SDK Supporter
 
iPhoneConnection's Avatar
 
Join Date: Apr 2010
Location: Sheffield
Posts: 144
iPhoneConnection is on a distinguished road
Default

I can't test that right now... however I'd be tempted to use:

HTML Code:
eventToAdd.startDate = [NSDate date];  // Set the start date to the current date/time.
eventToAdd.endDate = [NSDate dateWithTimeInterval:600.0f sinceDate:[eventToAdd startDate]];
rather than:

HTML Code:
eventToAdd.startDate = [[NSDate alloc] init];
eventToAdd.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:eventToAdd.startDate];
Your solution will cause a memory leak for both startDate and endDate as you've not released either NSDate objects or put them on the autorelease pool.

Last edited by iPhoneConnection; 11-19-2010 at 09:00 AM.
iPhoneConnection is offline   Reply With Quote
Old 11-19-2010, 09:18 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 11
bgp1 is on a distinguished road
Default

Thanks, I'll make those changes.
bgp1 is offline   Reply With Quote
Reply

Bookmarks

Tags
calendar, events, ical, iphone, rss

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 377
7 members and 370 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0