加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在Swift中使用Google Calendar API

发布时间:2020-12-14 04:54:58 所属栏目:百科 来源:网络整理
导读:我通过谷歌提供的 iOS Quickstart Guide工作,注意它已经过时了很长时间. 因此,我研究了一整天,以了解它现在应该如何工作,但我没有找到有关如何实现它的工作解决方案/说明. 我有一个带日历的iOS应用程序.用户可以决定应该使用哪个日历来同步应用和日历之间的
我通过谷歌提供的 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读