Sunday, 11 August 2013

display the eventtitle of the Mac OS X calendar

display the eventtitle of the Mac OS X calendar

#import "calCreate.h"
#import <EventKit/EventKit.h>
@implementation calCreate
-(void)awakeFromNib {
[self create];
[theLabel setStringValue:@"&#55357;&#56836;"];
}
-(void)create {
EKEventStore *store = [[EKEventStore alloc]
initWithAccessToEntityTypes:EKEntityMaskEvent];
// Get the appropriate calendar
NSCalendar *calendar = [NSCalendar currentCalendar];
//
//Create the start date components
NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
oneDayAgoComponents.day = -1;
NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents
toDate:[NSDate date]
options:0];
// Create the end date components
NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc]
init];
oneYearFromNowComponents.year = 1;
NSDate *oneYearFromNow = [calendar
dateByAddingComponents:oneYearFromNowComponents
toDate:[NSDate date]
options:0];
// Create the predicate from the event store's instance method
NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo
endDate:oneYearFromNow
calendars:nil];
//Fetch all events that match the predicate
NSArray *events = [store eventsMatchingPredicate:predicate];
NSDate *now;
now = [NSDate date];
}
For example,there is an event with the title "Learn it" on Aug.8 which is
written in Calendar.app on Mac.And I want to display the title using
objective-c(I am programming on Mac OS X,learning to make a Mac App
related to calendar.app).(For example,I want to NSLog the title but I
don't know how to get the information from Calendar)
I am a student in China fond of coding,and I have a little trouble finding
what I want to know .I sincerely hope you could help me or give me some
tips. Thank you.

No comments:

Post a Comment