gpt4 book ai didi

iphone - 如何使用 EKEvent?

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:29 25 4
gpt4 key购买 nike

NSDictionary *d = (NSDictionary *) [arrGarden objectAtIndex:0];
int intarrCount=0;

NSString *strDate =[NSString stringWithFormat:@"%@", [d valueForKey:@"open_date_for_calendar"]];

NSArray *arrDateList =[strDate componentsSeparatedByString:@","];


NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];



for(int i=0;i<[arrDateList count];i++)
{
intarrCount++;
EKEventStore *eventDB = [[EKEventStore alloc] init];

EKEvent *myEvent = [EKEvent eventWithEventStore:eventDB];

NSString *trimmedString = [[arrDateList objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// NSString *trimmedString = [NSString stringWithFormat:@"%@",[[arrDateList objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

myEvent.title = [d valueForKey:@"garden_name"];
myEvent.startDate = [dateFormatter dateFromString:trimmedString];
//myEvent.endDate = [dateFormatter dateFromString:trimmedString];
myEvent.endDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:myEvent.startDate];
myEvent.allDay = YES;

[myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];
NSError *err;
[eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err];
//NSString *eID = myEvent.eventIdentifier;


if(intarrCount == [arrDateList count])
{
if (err == noErr) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Event Added to your calendar"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}

在我使用的代码行之上..

当我将事件添加到日历时,事件在日历中添加成功,但在 10-15 秒后事件会自动删除...请帮助我在代码行中有错误的地方谢谢....

最佳答案

此代码用于添加事件。

-(IBAction)eventAddToiCal:(id)sender
{

if(txtTitle.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Enter Data" message:@"Please enter data into fields" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil ];
[alert show];
[alert release];
}
else
{
event = [EKEvent eventWithEventStore:eventStore];
event.startDate = startDate;
event.title = txtTitle.text;
event.location = txtLocation.text;
event.endDate = endDate;
event.notes = txtvNote.text;

/// tejas (Save Event in default Calendar of iPhone)
// Try to save the event

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *error = nil;
[self.eventsList addObject:event];
[eventStore saveEvent:event span:EKSpanThisEvent error:&error];
}
}

关于iphone - 如何使用 EKEvent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11755415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com