从目标c中的Google日历中获取特定事件

时间:2017-03-09 09:10:25

标签: ios objective-c google-calendar-api

我想从谷歌日历中获取特定事件。

这是我的代码:

- (void)fetchEvents {
    GTLQueryCalendar *query = [GTLQueryCalendar queryForEventsListWithCalendarId:calendarId];

    query.timeMin = [GTLDateTime dateTimeWithDate:startDate
                                     timeZone:[NSTimeZone timeZoneWithName:@"UTC"]];;
    query.timeMax = [GTLDateTime dateTimeWithDate:endDate timeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

    query.singleEvents = YES;
    query.orderBy = kGTLCalendarOrderByStartTime;

    [self.service executeQuery:query
                  delegate:self
          didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}

- (void)displayResultWithTicket:(GTLServiceTicket *)ticket
         finishedWithObject:(GTLCalendarEvents *)events
                      error:(NSError *)error {
    if (error == nil) {

        if (events.items.count > 0) {

        }
    }
   }

现在我可以在开始日期和结束日期之间获取事件。我创建了一个calendarEvent,从4月3日到4月5日,时间是下午3点到4点,活动名称是Meeting ...

现在我想知道这个事件是否已经存在。如果不存在,我可以添加。

如果用户删除了特定事件,我也想删除它。

怎么做?

1 个答案:

答案 0 :(得分:0)

调用Events.list,因为它会返回所有具有相应eventIds的事件。这样,您可以查看您创建的事件是否存在。

您可以查看指南中的code samples for Objective-C。这是一个片段:

// Construct a query and get a list of upcoming events from the user calendar. Display the
// start dates and event summaries in the UITextView.
- (void)fetchEvents {
  GTLQueryCalendar *query = [GTLQueryCalendar queryForEventsListWithCalendarId:@"primary"];
  query.maxResults = 10;
  query.timeMin = [GTLDateTime dateTimeWithDate:[NSDate date]
                                       timeZone:[NSTimeZone localTimeZone]];;
  query.singleEvents = YES;
  query.orderBy = kGTLCalendarOrderByStartTime;

  [self.service executeQuery:query
                    delegate:self
           didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}