我可以在iOS中向日历应用添加多少个事件?

时间:2013-02-19 07:09:56

标签: iphone ios objective-c eventkit

我使用此代码将事件添加到iOS上的日历应用

int i = 0;

for(Schedule *sche in scheduleArray){ 
EKEventStore *eventStore=[[EKEventStore alloc] init];
EKEvent *addEvent=[EKEvent eventWithEventStore:eventStore];
addEvent.title=@"hello";
addEvent.startDate=[NSDate date];
addEvent.endDate=[addEvent.startDate dateByAddingTimeInterval:600];  
[addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];  

addEvent.alarms=[NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]];

NSError *err;
[eventStore saveEvent:addEvent span:EKSpanThisEvent error:&err];
if (err == nil) {
    NSString* str = [[NSString alloc] initWithFormat:@"%@", addEvent.eventIdentifier];

    NSLog(@"String %d: %@",i, str);
}
else { 
    NSLog(@"Error %@",err);
}
i++;     
}

我想在scheduleArray中添加我之前保存的数据的所有事件,我在scheduleArray中有86个对象,但似乎我只向日历添加了大约82个事件。这是我的日志结果:

.......
2013-02-19 14:04:28.237 MyDTUSchedule[5382:6607] String 67: BBCF7782-5D60-42D7-8478-EF80604FBF41:4A9E6404-B35B-4534-A7F2-5C6082F3D19A
2013-02-19 14:04:28.284 MyDTUSchedule[5382:6607] String 68: BBCF7782-5D60-42D7-8478-EF80604FBF41:47F0B6CF-3F98-49F9-B407-7A28B4F12C83
2013-02-19 14:04:28.343 MyDTUSchedule[5382:6607] String 69: BBCF7782-5D60-42D7-8478-EF80604FBF41:FB802E03-876D-4ADB-93B9-C3FAB628FF57
2013-02-19 14:04:28.412 MyDTUSchedule[5382:6607] String 70: BBCF7782-5D60-42D7-8478-EF80604FBF41:21786B81-BAC8-4979-9A04-B63CE404B870
2013-02-19 14:04:28.479 MyDTUSchedule[5382:6607] String 71: BBCF7782-5D60-42D7-8478-EF80604FBF41:9CF1DDA5-B8F3-4835-A5BC-A9FE745E17D1
2013-02-19 14:04:28.503 MyDTUSchedule[5382:6607] String 72: BBCF7782-5D60-42D7-8478-EF80604FBF41:834BE2CE-E810-4EA7-ACFC-01FAAA46453E
2013-02-19 14:04:28.580 MyDTUSchedule[5382:6607] String 73: BBCF7782-5D60-42D7-8478-EF80604FBF41:BFBDBECF-1A31-4363-9FD2-66C05F4085B9
2013-02-19 14:04:28.629 MyDTUSchedule[5382:6607] String 74: BBCF7782-5D60-42D7-8478-EF80604FBF41:3512265D-10A9-40AE-8435-0BDBC1D72A1B
2013-02-19 14:04:28.690 MyDTUSchedule[5382:6607] String 75: BBCF7782-5D60-42D7-8478-EF80604FBF41:96C68CAC-2955-4EDD-8FE2-442CDDDE39A8
2013-02-19 14:04:28.733 MyDTUSchedule[5382:6607] String 76: BBCF7782-5D60-42D7-8478-EF80604FBF41:2724EBFD-AB03-4E6A-8094-25D7035B517C
2013-02-19 14:04:28.818 MyDTUSchedule[5382:6607] String 77: BBCF7782-5D60-42D7-8478-EF80604FBF41:CC14386F-E21A-41AA-82D5-42B05149EB09
2013-02-19 14:04:28.865 MyDTUSchedule[5382:6607] String 78: BBCF7782-5D60-42D7-8478-EF80604FBF41:3738B384-21B9-4544-8DD2-C50032B5404D
2013-02-19 14:04:28.929 MyDTUSchedule[5382:6607] String 79: BBCF7782-5D60-42D7-8478-EF80604FBF41:70F820A8-37A5-4CC1-8E0E-696736CABC2C
2013-02-19 14:04:28.964 MyDTUSchedule[5382:6607] String 80: BBCF7782-5D60-42D7-8478-EF80604FBF41:864E4DEF-275F-4458-A5E2-A136C2F57982
2013-02-19 14:04:29.019 MyDTUSchedule[5382:6607] String 81: BBCF7782-5D60-42D7-8478-EF80604FBF41:061BF4AE-6BD5-4B3E-B2FC-35A18A7D99A5
2013-02-19 14:04:29.042 MyDTUSchedule[5382:6607] Error Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0xe21da30 {NSLocalizedDescription=No calendar has been set.}
2013-02-19 14:04:29.052 MyDTUSchedule[5382:6607] Error Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0xe1551d0 {NSLocalizedDescription=No calendar has been set.}
2013-02-19 14:04:29.054 MyDTUSchedule[5382:6607] Error Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0xe21bf90 {NSLocalizedDescription=No calendar has been set.}
2013-02-19 14:04:29.058 MyDTUSchedule[5382:6607] Error Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0xe21abd0 {NSLocalizedDescription=No calendar has been set.}

我不知道为什么会发生这些错误?如何将我的所有活动添加到日历中?

0 个答案:

没有答案