从我们的应用程序管理 iPhone 日历事件

发布于 2024-11-19 18:24:47 字数 3196 浏览 5 评论 0原文

以下是我的代码

NSLog(@"%@", thisEvent1.title); 

EKEvent *thisEvent  = [EKEvent eventWithEventStore:eventStore];

eventStore = [[EKEventStore alloc] init];

thisEvent = [EKEvent eventWithEventStore:eventStore];


NSDateFormatter *   dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd:HH:mm"];


NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
[date retain];

thisEvent.startDate = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
thisEvent.endDate = [dateFormatter dateFromString:[itsEndDate objectAtIndex:indexPath.row]];
thisEvent.notes = [itsNotes objectAtIndex:indexPath.row];
thisEvent.title = [itsTitle objectAtIndex:indexPath.row];
thisEvent.location = [itsLocation objectAtIndex:indexPath.row];
// thisEvent.allDay = TRUE;
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];

EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-[[itsAlertOne objectAtIndex:indexPath.row] intValue]]; // 1 Hour
// EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day

[myAlarmsArray addObject:alarm1];
//[myAlarmsArray addObject:alarm2];

thisEvent.alarms = myAlarmsArray;
[myAlarmsArray release];

//setting the Reuccurence rule

NSString * test1 = [itsRecurrenceFrequency objectAtIndex:indexPath.row];

    BOOL isRecurrenceFrequencyExists = TRUE;

EKRecurrenceFrequency  recurrenceFrequency;

if ([test1 isEqualToString: @"EKRecurrenceFrequencyDaily"]) {
    recurrenceFrequency = EKRecurrenceFrequencyDaily;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyWeekly"]){
    recurrenceFrequency = EKRecurrenceFrequencyWeekly;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyMonthly"]){
    recurrenceFrequency = EKRecurrenceFrequencyMonthly;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyYearly"]){
    recurrenceFrequency = EKRecurrenceFrequencyYearly;
}else{
    isRecurrenceFrequencyExists = FALSE;
}

    if(isRecurrenceFrequencyExists){
        EKRecurrenceRule * recurrenceRule = [[EKRecurrenceRule alloc] 

                                     initRecurrenceWithFrequency:recurrenceFrequency
                                     interval:[[itsRecurrenceInterval objectAtIndex:indexPath.row]intValue]
                                     end:nil];
        if (thisEvent.endDate != nil) {
            EKRecurrenceEnd * end = [EKRecurrenceEnd recurrenceEndWithEndDate:thisEvent.endDate];
            recurrenceRule.recurrenceEnd = end;
        }else {
            thisEvent.endDate = thisEvent.startDate;
        }

        thisEvent.recurrenceRule = recurrenceRule;
        [recurrenceRule release];

    }
[thisEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;


[eventStore saveEvent:thisEvent span:EKSpanFutureEvents error:&err]; 
NSLog(@"%@", thisEvent.eventIdentifier);
[self.eventsList addObject:thisEvent];

在此代码中,我有日历事件的事件 ID。

  1. 现在我想用更改来更新事件,但是它不会更新以前创建的事件。

  2. 第二,我需要知道是否可以捕获他们在 iPhone 日历中所做的日历事件的更改,包括删除事件。

  3. 我们可以使用 eventid 删除日历事件吗?

如果有人知道答案,请帮助我。先谢谢你。

问候, 迪利普·拉吉库马尔

The following is my code

NSLog(@"%@", thisEvent1.title); 

EKEvent *thisEvent  = [EKEvent eventWithEventStore:eventStore];

eventStore = [[EKEventStore alloc] init];

thisEvent = [EKEvent eventWithEventStore:eventStore];


NSDateFormatter *   dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd:HH:mm"];


NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
[date retain];

thisEvent.startDate = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
thisEvent.endDate = [dateFormatter dateFromString:[itsEndDate objectAtIndex:indexPath.row]];
thisEvent.notes = [itsNotes objectAtIndex:indexPath.row];
thisEvent.title = [itsTitle objectAtIndex:indexPath.row];
thisEvent.location = [itsLocation objectAtIndex:indexPath.row];
// thisEvent.allDay = TRUE;
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];

EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-[[itsAlertOne objectAtIndex:indexPath.row] intValue]]; // 1 Hour
// EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day

[myAlarmsArray addObject:alarm1];
//[myAlarmsArray addObject:alarm2];

thisEvent.alarms = myAlarmsArray;
[myAlarmsArray release];

//setting the Reuccurence rule

NSString * test1 = [itsRecurrenceFrequency objectAtIndex:indexPath.row];

    BOOL isRecurrenceFrequencyExists = TRUE;

EKRecurrenceFrequency  recurrenceFrequency;

if ([test1 isEqualToString: @"EKRecurrenceFrequencyDaily"]) {
    recurrenceFrequency = EKRecurrenceFrequencyDaily;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyWeekly"]){
    recurrenceFrequency = EKRecurrenceFrequencyWeekly;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyMonthly"]){
    recurrenceFrequency = EKRecurrenceFrequencyMonthly;
}else if([test1 isEqualToString: @"EKRecurrenceFrequencyYearly"]){
    recurrenceFrequency = EKRecurrenceFrequencyYearly;
}else{
    isRecurrenceFrequencyExists = FALSE;
}

    if(isRecurrenceFrequencyExists){
        EKRecurrenceRule * recurrenceRule = [[EKRecurrenceRule alloc] 

                                     initRecurrenceWithFrequency:recurrenceFrequency
                                     interval:[[itsRecurrenceInterval objectAtIndex:indexPath.row]intValue]
                                     end:nil];
        if (thisEvent.endDate != nil) {
            EKRecurrenceEnd * end = [EKRecurrenceEnd recurrenceEndWithEndDate:thisEvent.endDate];
            recurrenceRule.recurrenceEnd = end;
        }else {
            thisEvent.endDate = thisEvent.startDate;
        }

        thisEvent.recurrenceRule = recurrenceRule;
        [recurrenceRule release];

    }
[thisEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;


[eventStore saveEvent:thisEvent span:EKSpanFutureEvents error:&err]; 
NSLog(@"%@", thisEvent.eventIdentifier);
[self.eventsList addObject:thisEvent];

In this code I have the Event id of my calendar event.

  1. Now I want to update the event with the changes however Its not updating the previously created event.

  2. Second I Need to know is it possible to capture the changes in calendar event they made in iPhone Calendar including deleting an event.

  3. Can we delete the calendar event using the eventid?

Please help me if any one know the answer.. Thank you in advance.

Regards,
Dilip Rajkumar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-11-26 18:24:47

可以通过以下方式创建事件:

[eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
   NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
[arrayofCalIDs addObject:str];

您可以使用以下方式删除事件:

EKEventStore* store = [[[EKEventStore alloc] init] autorelease];
   EKEvent* event2 = [store eventWithIdentifier:[arrayofCalIDs objectAtIndex:i]];
if (event2 != nil) {  
  NSError* error = nil;
  [store removeEvent:event2 span:EKSpanThisEvent error:&error];
} 
[myPath release];

For Updating Event you cannot directly access any method as it is not available in iOS. So, you can do one thing for this. 
(1) First remove the event with eventID.
(2) Create new Event using the same information of the last deleted event.

Event can be created by this:

[eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
   NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
[arrayofCalIDs addObject:str];

You can delete the event using this:

EKEventStore* store = [[[EKEventStore alloc] init] autorelease];
   EKEvent* event2 = [store eventWithIdentifier:[arrayofCalIDs objectAtIndex:i]];
if (event2 != nil) {  
  NSError* error = nil;
  [store removeEvent:event2 span:EKSpanThisEvent error:&error];
} 
[myPath release];

For Updating Event you cannot directly access any method as it is not available in iOS. So, you can do one thing for this. 
(1) First remove the event with eventID.
(2) Create new Event using the same information of the last deleted event.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文