1

プログラムで iPhone カレンダーのすべてのイベントを読み取る方法を知りたいですか?

既知の日のイベントを取得する方法を知っています。次のコードは、現在の日付のイベントを取得します。しかし、iPhoneカレンダーに保存されているすべてのイベントを取得するにはどうすればよいですか. 日付によらない?

NSDate *startDate = [NSDate date];

// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:(86400*1)];

// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray]; 

// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicateredicate];
4

3 に答える 3

1

ユーザーのカレンダー データベースからイベントを取得するには、次の 3 つの方法があります。1) イベント ストアとしてイベントを取得する 2) 述語を使用してイベントを取得する 3) 識別子を使用して個々のイベントを取得する

Predicate または Identifier のいずれかを使用できます。IOS ガイドラインに従って、いくつかの例と詳細を確認してください。

これが役立つことを願っています。

于 2011-05-20T04:19:55.690 に答える
1

この bello コードは、デバイス カレンダーからすべてのカレンダー イベントを取得するために使用されます。以下のコードをコピーして貼り付けるだけで、すべてのイベントを取得できます。

EventKitUI/EventKitUI.h-> このファイルをインポート

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if(granted) {
        NSDate* startDate = /* whatever value you want */
        NSDate* endDate = /* whatever value you want */
        NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];
        NSArray *eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
        NSLog(@"allevent:%@",eventList);
    }
}];
于 2013-12-23T10:44:18.367 に答える
0
NSDate* startDate = [NSDate distantPast];
NSDate* endDate = [NSDate distantFuture];
于 2011-05-09T09:48:32.213 に答える