微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Swift中使用Google Calendar API

我通过谷歌提供的 iOS Quickstart Guide工作,注意它已经过时了很长时间.

因此,我研究了一整天,以了解它现在应该如何工作,但我没有找到有关如何实现它的工作解决方案/说明.

我有一个带日历的iOS应用程序.用户可以决定应该使用哪个日历来同步应用和日历之间的日历事件.应支持Google日历和Apple日历. Apple Calendar同步工作正常.对于Google日历,我还找不到任何解决方案.谷歌日历的用户应该可以将所有事件与我们的iOS应用程序同步(包括添加,删除和更改事件).

对于那些没有过时的内容是否有任何来源,并且描述了如何做到这一点?

解决方法

Google在Github上有一个示例应用程序: https://github.com/google/google-api-objectivec-client-for-rest

如果你仔细阅读应用程序,有一个创建事件的Objective-C示例,它应该为你提供一个开始Swift的好地方:

- (void)addEvent:(GTLRCalendar_Event *)event {
  GTLRCalendarService *service = self.calendarService;
  GTLRCalendar_CalendarListEntry *selectedCalendar = [self selectedCalendarListEntry];
  Nsstring *calendarID = selectedCalendar.identifier;

  GTLRCalendarQuery_EventsInsert *query =
      [GTLRCalendarQuery_EventsInsert queryWithObject:event
                                           calendarId:calendarID];
  self.editEventTicket = [service executeQuery:query
                             completionHandler:^(GTlrserviceTicket *callbackTicket,GTLRCalendar_Event *event,NSError *callbackerror) {
     // Callback
     self.editEventTicket = nil;
     if (callbackerror == nil) {
       [self displayAlert:@"Event Added"
                   format:@"Added event \"%@\"",event.summary];
       [self fetchSelectedCalendar];
     } else {
       [self displayAlert:@"Add Failed"
                   format:@"Event add Failed: %@",callbackerror];
     }
   }];
}

此外,您还可以使用EventKit并让用户按照自己的意愿同步日历,如下所述:ios Add Event to google calendar

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐