在保存超过100个ekevents后,应用程序崩溃并重新启动Iphone

时间:2014-04-08 14:35:52

标签: ios objective-c ekevent

我正在研究Ekevents,我的应用程序崩溃并且在添加超过100个事件后Iphone重启,当应用崩溃时出现此错误消息“接收内存警告终止以响应SpringBoard的终止” < / p>

for (int i=0; i<120; i++) {

    NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
    dayComponent.day = 7*incrementedWeek;
    incrementedWeek++;
    NSCalendar *theCalendar = [NSCalendar currentCalendar];

    NSDate* dateIncrementByWeek = [theCalendar dateByAddingComponents:dayComponent toDate:dateToBeIncremented options:0];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];

        NSDate* dateIncrementByWeek = [theCalendar dateByAddingComponents:dayComponent toDate:dateToBeIncrementedWeekDay1 options:0];
        NSCalendar *calendar1 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents *components = [calendar1 components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:dateIncrementByWeek];
        [components setHour:17];
        [components setMinute:30];
        NSDate *date1 = [calendar1 dateFromComponents:components];
        [components setHour:20];
        [components setMinute:30];
        NSDate *date2 = [calendar1 dateFromComponents:components];
 NSDate *date22 = [calendar1 dateFromComponents:components];

        EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-3600.0f];
        [event addAlarm:alarm];
        event.calendar = calendar;
        event.title = @"title";

        // set the start date to the current date/time and the event duration to two hours
        //  NSDate *startDate = eventDate;
        event.startDate = date1;
        event.endDate = date2;

 //NSLog(@"optianl date1 %@",date1);
 //NSLog(@"optianl date2 %@",date2);
        NSError *error = nil;
        // save event to the callendar
        BOOL result = [eventStore saveEvent:event span:EKSpanThisEvent commit:NO error:&error];
 [eventStore commit:NULL];

        if (result) {
              NSLog(@"Event created");
        } else {
             NSLog(@"Event created");


        }

1 个答案:

答案 0 :(得分:0)

即使我遇到同样的问题,后来发现我添加了超过64个通知,因此重新加载时发生了崩溃。

因此,在取消所有本地通知后,最多添加64个通知,它应该可以正常工作。

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html