Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Calendar API in Swift

I worked through the iOS Quickstart Guide provided by google to notice, that it is outdated for a very long time already.

So I researched the whole day to find out how it is supposed to work now but I did not find a working solution / description on how to do it.

I have an iOS App with a calendar. The user can decide which calendar should be used to synchronise calendar events between app and calendar. Google Calendar and Apple Calendar should be supported. The Apple Calendar synchronisation is working perfectly. For the Google Calendar I could not find any solution yet. It should be possible for users of an google calendar to synchronize all events with our iOS app (including adding, removing and changing events).

Is there any source for that which is not outdated and which is describing on how to do it?

like image 986
Mulgard Avatar asked Apr 18 '17 14:04

Mulgard


1 Answers

Google has an example app on Github here: https://github.com/google/google-api-objectivec-client-for-rest

If you dig through the app, there's an Objective-C example of creating an event, it should give you a good place to start for Swift as well:

- (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];
     }
   }];
}

Additionally, you can also use the EventKit and let the user sync their calendar as they see fit, as described here: ios Add Event to google calendar

like image 175
Adis Avatar answered Oct 05 '22 07:10

Adis