ios Add Event to google calendar

2019-04-11 02:06发布

问题:

I have searching how to add event t users google calendar. In my project I have database with events(title,startDate,endDate etc). When user clicks sync button all this events should be add to users google calendar.

I downloaded api from here. But its for MAC OS. Since I never worked on MAC OS application I cant understand how to use it in IOS app.

Please help me and tell which view controller to use asking for username and password, then login to google calendar service and add event in it.

Thank you.

I got http://code.google.com/p/google-api-objectivec-client/. But its difficult to understand. It takes username and password from preferences. Then gets calendars and adds events, but to add we need ticket and some more things. This code did some things.

In their add event method I wrote my own event object and tried to add that, but its not working. Here is the code:

- (void)insertCalendarEvent:(GDataEntryCalendarEvent *)event toCalendar:(GDataEntryCalendar *)calendar
{
    NSLog(@"adding event");

    GDataDateTime *time = [GDataDateTime dateTimeWithDate:[NSDate date] timeZone:(NSTimeZone*)[NSTimeZone timeZoneForSecondsFromGMT:0]];

    GDataEntryCalendarEvent *newEntry = [GDataEntryCalendarEvent calendarEvent];
    [newEntry setTitleWithString:@"title"];
    [newEntry addLocation:[GDataWhere whereWithString:@"pune"]];
    [newEntry addTime:[GDataWhen whenWithStartTime:time endTime:time]];

  [googleCalendarService fetchEntryByInsertingEntry:newEntry
                                         forFeedURL:[[calendar alternateLink] URL]
                                           delegate:self
                                  didFinishSelector:@selector( insertTicket:finishedWithEntry:error: )];

}

My requirement is simple. I just want add my custom events to google calendar. Get calendar, get ticket, and in for loop add all my events.

回答1:

Instead of using Google API and a new window where the user needs to be login again, you should use the EventKit, it's pretty easy stuff and you could sync to the Calendar where the user wants, not only Google cal.



回答2:

As @Tuss Laszlo mentioned, the Google API Client library is your best option to add events only to a Google Calendar. Google has a calendar sample in their example code. See the example for the full implementation of adding calendar events.



回答3:

I have the same requirement like yours to integrate google calendar and syncing events. I researched and found documentation from here but I didn't understand it clearly, so later I found another good tutorial for accessing google calendar API's. You can try this for your requirement.