2017-04-18 166 views
5

我通过谷歌提供的iOS Quickstart Guide工作,发现它已经过时很长一段时间了。在Swift中使用谷歌日历API

所以我研究了一整天,以了解它现在应该如何工作,但我没有找到有关如何去做的工作解决方案/描述。

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

是否有任何来源,这是不是过时,并描述如何做到这一点?

回答

0

谷歌已经在这里Github上的示例应用程序:https://github.com/google/google-api-objectivec-client-for-rest

如果通过应用挖,有创建事件的Objective-C的例子,它应该给你一个良好的开端对于斯威夫特,以及:

- (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

+0

可以ü添加事件中迅速@Adis –

+0

谷歌日历提供代码C你应该告诉我 –