Mul*_*ard 6 calendar google-calendar-api swift
我通过谷歌提供的iOS快速入门指南工作,注意它已经过时了很长时间.
因此,我研究了一整天,以了解它现在应该如何工作,但我没有找到有关如何实现它的工作解决方案/说明.
我有一个带日历的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];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
此外,您还可以使用 EventKit 并让用户根据需要同步其日历,如下所述:ios 将事件添加到 google 日历