在日历事件的alertView中设置我自己的消息

时间:2011-07-14 11:16:40

标签: iphone ipad ios4 calendar

我目前正在使用EKEventEKEevntUI框架, 我的问题是:是否可以在UIAlertView中为日历事件设置我自己的消息?

谢谢,

1 个答案:

答案 0 :(得分:0)

//set event reminder
//make sure to import EventKit framework

    EKEventStore *eventDB = [[[EKEventStore alloc] init]autorelease];
    EKEvent *myEvent  = [EKEvent eventWithEventStore:eventDB];
    NSString * eventTitle = @"This is your custom title";
    myEvent.title = eventTitle;



//set event time frame (1 hour) the "initWithTimeInterval" is where we account for the users timezone by adding the correctedTime from GMT to the calendar time ( so its not off by hours when entering into calendar)
    myEvent.startDate = [[[NSDate alloc] initWithTimeInterval:correctedTimeForCalendarEvent sinceDate:destinationDate ]autorelease];
    myEvent.endDate   = [[[NSDate alloc] initWithTimeInterval:3600 sinceDate:myEvent.startDate]autorelease];
    myEvent.allDay = NO;

//set event reminders 1 day and 1 hour before
    myAlarmsArray = [[[NSMutableArray alloc] init] autorelease];
    EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-3600]; // 1 Hour
    EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day
    [myAlarmsArray addObject:alarm1];
    [myAlarmsArray addObject:alarm2];
    myEvent.alarms = myAlarmsArray;



    [myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];

    NSError *err;

    [eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err]; 

    if (err == noErr) {
        //no error, but do not show alert because we do that below.
    }