1

我第一次尝试编辑一些objective-c。
我正在尝试编辑将日期添加到 iPhone 日历中的 phonegap 日历插件,但由于我的日期没有结束时间,我想对其进行编辑,以便它会在开始时间后 2 小时自动设置结束时间

NSString* title      = [arguments objectAtIndex:1];
NSString* location   = [arguments objectAtIndex:2];
NSString* message    = [arguments objectAtIndex:3];
NSString *startDate  = [arguments objectAtIndex:4];
//NSString *endDate    = [arguments objectAtIndex:5];

//creating the dateformatter object
NSDateFormatter *sDate = [[[NSDateFormatter alloc] init] autorelease];
[sDate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *myStartDate = [sDate dateFromString:startDate];

//NSDateFormatter *eDate = [[[NSDateFormatter alloc] init] autorelease];
//[eDate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//NSDate *myEndDate = [eDate dateFromString:endDate];
NSDate *myEndDate = [myStartDate dateByAddingTimeInterval:  2*60*60];

myEvent.title = title;
myEvent.location = location;
myEvent.notes = message;
myEvent.startDate = myStartDate;
myEvent.endDate = myEndDate;
myEvent.calendar = store.defaultCalendarForNewEvents;

我没有收到任何错误,但是当我测试我的应用程序时,它不再将日期添加到日历中。

4

0 回答 0