addCalendarRemid:(NSString*)noticeTime noticeCont:(NSString*)noticeCont noticeAddr:(NSString*)noticeAddr noticeMinute:(NSString*)noticeMinute
{
// Get the event store object
EKEventStore *eventStore = [[EKEventStore alloc] init];
// Create a new event
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
// Create NSDates to hold the start and end date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *stDate = [dateFormatter dateFromString:@"2012-01-01 12:02:12"];
[dateFormatter release];
// NSDate *stDate =[[NSDate alloc] initWithTimeIntervalSince1970:[noticeTime doubleValue]/1000];
NSDate *startDate = [[[NSDate alloc]init]autorelease];
startDate = [stDate dateByAddingTimeInterval:60*60*0];
// Set properties of the new event object
event.title = noticeCont;
event.startDate = startDate;
event.endDate = [startDate initWithTimeInterval:60*90 sinceDate:startDate];
event.allDay = NO;
[event setLocation:noticeAddr];
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-60*[noticeMinute intValue]];
// 1 minutes
// EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day
[myAlarmsArray addObject:alarm1];
//[myAlarmsArray addObject:alarm2];
//EKRecurrenceEnd *endd = [EKRecurrenceEnd recurrenceEndWithEndDate:[stDate dateByAddingTimeInterval:60*24*7*30]];
EKRecurrenceRule *rule = [[EKRecurrenceRule alloc]initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly interval:1 end:nil];
NSMutableArray *myrulesArray = [[NSMutableArray alloc] init];
[myrulesArray addObject:rule];
[event setRecurrenceRules:myrulesArray];
event.alarms = myAlarmsArray;
[myAlarmsArray release];
// set event's calendar to the default calendar
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
// Save the event
//[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
// NSString* strIdentifier = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
// NSMutableArray *arrayofCalIDs = [[[NSMutableArray alloc]initWithObjects:strIdentifier, nil] autorelease];
//[[NSUserDefaults standardUserDefaults] setObject:arrayofCalIDs forKey:@"tmp"];
// Create an NSError pointer
if (err == noErr) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"友情提示"
message:@"您可以去日历中查看电影开始时间和地点"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
NSMutableArray *arrayofCalIDs_ = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"tmp"]];
EKEvent* event2 = [eventStore eventWithIdentifier:[arrayofCalIDs_ objectAtIndex:0]];
if (event2 != nil) {
NSError* error = nil;
[eventStore removeEvent:event2 span:EKSpanThisEvent||EKSpanFutureEvents error:&error];
}
[eventStore release];
}