3

ボタンを介して患者に予約を思い出させるアプリケーションがあります。患者がボタンをクリックした場合、患者カレンダーのすべてのイベントを取得して、予約が既に存在するかどうかを確認します。存在しない場合は、イベントを作成します。

イベントをカレンダーに追加する方法は知っていますが、フェッチはゼロカウントを返しますか??

以下は私のコードです:

 //set start and end date
NSDate* startDate = [NSDate date];//start from today
NSDate* endDate =  [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];//no end
NSLog(@"S Date %@", startDate);
NSLog(@"E Date %@", endDate);

NSString *AppointmentTitle=@"Appointment in Hospital at Pediatric Clinic";

EKEventStore *store = [[EKEventStore alloc] init];
NSArray *calendarArray = [store calendars];
NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
NSArray *eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
BOOL IsFound;
int EventsCount=eventList.count;
for(int i=0; i < EventsCount; i++)
{
    NSLog(@"Event Title:%@", [[eventList objectAtIndex:i] title]);
    if ([[[eventList objectAtIndex:i] title] isEqualToString:AppointmentTitle])//check title
    {
        IsFound=TRUE;
        break;
    }
    else
    {
        IsFound=FALSE;
    }
}

このコードは 2 か月前は問題なく動作していました。突然、戻ってテストしたところ、機能しませんでした。私は何か見落としてますか?または私のコードに間違いはありますか?

私はあなたの助けが必要ですplz..

4

1 に答える 1

10

Finaaaaaaaally 私は答えを得ました、私は Apple が許可を得て何かをしたと思います (iOS 5 では、リマインダー (EKEntityTypeReminder) にアクセスできる iOS 6 とは異なり、イベントストアのイベント (EKEntityTypeEvent) にしかアクセスできません。しかし、あなたは必要です以下のコードは、少なくとも 1 回は付与されます。)「WrightsCS による回答」

以下のコードを見つけてください:-

   EKEventStore *store = [[EKEventStore alloc] init];


// Get the appropriate calendar
NSCalendar *calendar = [NSCalendar currentCalendar];


if ([store respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
    /* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
     {
         if ( granted )
         {
             NSLog(@"User has granted permission!");
             // Create the start date components
             NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
             oneDayAgoComponents.day = -1;
             NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents
                                                           toDate:[NSDate date]
                                                          options:0];

             // Create the end date components
             NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init];
             oneYearFromNowComponents.year = 1;
             NSDate *oneYearFromNow = [calendar dateByAddingComponents:oneYearFromNowComponents
                                                                toDate:[NSDate date]
                                                               options:0];

             // Create the predicate from the event store's instance method
             NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo
                                                                     endDate:oneYearFromNow
                                                                   calendars:nil];

             // Fetch all events that match the predicate
             NSArray *events = [store eventsMatchingPredicate:predicate];
             NSLog(@"The content of array is%@",events);
         }
         else
         {
             NSLog(@"User has not granted permission!");
         }
     }];
}
于 2013-04-11T14:21:56.870 に答える