0

イベントは、イベント開始時刻の10秒前(テスト目的)に再生されるアラームで正常に追加されます。問題は、アラームがトリガーされる(iPhoneのUIAlertViewが表示される)が、1秒以内に消えることです。非常に奇妙な...

何が問題なのですか?

コード:

- (IBAction)addEvent:(id)sender {
    EKEventStore *eventStore = [[EKEventStore alloc] init];

    if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
    {
        [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
             EKEvent *anEvent = [EKEvent eventWithEventStore:eventStore];
             anEvent.calendar = eventStore.defaultCalendarForNewEvents;
             anEvent.title = self.eventNameTextField.text;

             NSDate *date = self.datePicker.date;

             anEvent.startDate = date;
             anEvent.endDate = date;

             NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];

             EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-10];

             [myAlarmsArray addObject:alarm1];

             anEvent.alarms = myAlarmsArray;

             NSError *eventError;
             [eventStore saveEvent:anEvent span:EKSpanThisEvent error:&eventError];
         }];
    }
}
4

1 に答える 1

0

次のコードを参照してください。

 EKEventStore *eventStore = [[EKEventStore alloc] init];  
    EKEvent *event = [EKEvent eventWithEventStore:eventStore];
   event.title  = [NSString stringWithFormat:@"%@'s Birthday",strName];
   NSDate *twoYearsFromNow = [NSDate dateWithTimeIntervalSinceNow:1577846275];
    double alarmAmountInSeconds = 60*60*9;
   EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:(1.0*alarmAmountInSeconds)];
   EKRecurrenceRule *recurrance;
   recurrance = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyYearly interval:1 end:[EKRecurrenceEnd recurrenceEndWithEndDate:twoYearsFromNow]];
   NSMutableArray *arrayReccurence = [NSMutableArray arrayWithObject:recurrance];
   event.recurrenceRules = arrayReccurence;
   event.startDate = startDate;
    event.endDate  = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
   event.allDay = true;
    event.alarms = [NSArray arrayWithObject:alarm];

   [event setCalendar:[eventStore defaultCalendarForNewEvents]];
   NSError *err;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
于 2012-11-22T11:17:35.713 に答える