【问题标题】:How do I get start date, end date and location of an EKEventStore function如何获取 EKEventStore 函数的开始日期、结束日期和位置
【发布时间】:2014-03-28 13:05:32
【问题描述】:

我有这段代码可以从日历应用程序中读取日历数据。

EKEventStore *store = [[EKEventStore alloc] init];
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,
                                                                    NSError *error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Import" message:@"Import Unavailable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }];

    NSCalendar *calendar = [NSCalendar currentCalendar];
    // 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];
    for (id name in events)
        NSLog (@"%@", name);

它记录输出结果的完整详细信息:

EKEvent <0x937c410>
{    title =        Meeting w/ David; 
     location =     (null); 
     calendar =     EKCalendar <0x938a650> {title = Calendar; type = Local; allowsModify = YES; color = #1BADF8;}; 
     alarms =       (null); 
     URL =          (null); 
     lastModified = 2014-03-27 11:52:39 +0000; 
     timeZone =     Asia/Manila (GMT+8) offset 28800 
}; 
     location =     (null); 
     startDate =    2014-03-28 04:00:00 +0000; 
     endDate =      2014-03-28 05:00:00 +0000; 
     allDay =       0; 
     floating =     0; 
     recurrence =   (null); 
     attendees =    (null) 
};

我想要的是,我只想在 3 个单独的数组上获取开始日期、结束日期和位置。我如何获得这些?

【问题讨论】:

    标签: ekeventstore


    【解决方案1】:

    苦男孩:( 这是我的问题的答案:

    修改最后的代码为

    NSArray *events = [store eventsMatchingPredicate:predicate];
        for (id name in events){
            NSString *theName = [name valueForKey:@"title"];
            NSLog (@"%@", theName);
            //NSLog (@"%@", name);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多