I am trying to add events to google calendar but in ios 10 i am getting following error even i login my gmail account in settings --> calendar.
I am using the following code
GTLServiceCalendar *_calendarService = [[GTLServiceCalendar alloc] init];
_calendarService.authorizer = [GTMOAuth2ViewControllerTouch
authForGoogleFromKeychainForName:kGoogleAPIKeychainItemName
clientID:kGoogleAPIClientID
clientSecret:nil];
if (!_calendarService.authorizer.canAuthorize)
//if([auth canAuthorize])
{
[self launchGoogleAuthenticationView];
}
else {
[self addEventToGoogleCalendar];
}
- (void)launchGoogleAuthenticationView {
_didCancelGoogleAuthentication = NO;
GTMOAuth2ViewControllerTouch *authController;
// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeCalendar, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:@" "]
clientID:kGoogleAPIClientID
clientSecret:nil
keychainItemName:kGoogleAPIKeychainItemName
delegate:self
finishedSelector:@selector(googleAuthenticationViewController:finishedWithAuth:error:)];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setTitle:@"Cancel" forState:UIControlStateNormal];
[closeButton setBackgroundColor:appredcolor];
[closeButton addTarget:self
action:@selector(didTapCloseButton:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *closeButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:closeButton];
[closeButtonItem setTintColor:appredcolor];
[authController.navigationItem setLeftBarButtonItem:closeButtonItem];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:authController];
[myappDelegate.navCont.viewControllers.lastObject presentViewController:navController animated:YES completion:nil];
}
- (void)addEventToGoogleCalendar {
NSString *appdatestr =[[CTManager sharedInstance] getAppointmentForId:cardict.carsIdentifier];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"dd-MMM-yy, hh:mm a"];
_calendarEvent = [[GTLCalendarEvent alloc] init];
[_calendarEvent setSummary:@"Fathik"];
[_calendarEvent setDescriptionProperty:@"Adding event in UCR"];
NSDate *startDate = [outputFormatter dateFromString:appdatestr];
NSDate *endDate = [startDate dateByAddingTimeInterval:60*60];
if (endDate == nil) {
endDate = [startDate dateByAddingTimeInterval:(60 * 60)];
}
GTLDateTime *startTime = [GTLDateTime dateTimeWithDate:startDate
timeZone:[NSTimeZone systemTimeZone]];
[_calendarEvent setStart:[GTLCalendarEventDateTime object]];
[_calendarEvent.start setDateTime:startTime];
GTLDateTime *endTime = [GTLDateTime dateTimeWithDate:endDate
timeZone:[NSTimeZone systemTimeZone]];
[_calendarEvent setEnd:[GTLCalendarEventDateTime object]];
[_calendarEvent.end setDateTime:endTime];
GTLQueryCalendar *insertQuery = [GTLQueryCalendar queryForEventsInsertWithObject:_calendarEvent
calendarId:kGoogleAPICalendarID];
//[self showAlertWithTitle:nil
// andMessage:NSLocalizedString(@"Adding Event…", nil)];
[_calendarService executeQuery:insertQuery
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (error == nil) {
NSLog(@"event added");
[myappDelegate.navCont.view makeToast:@"Event added to your Calender"
duration:2.0
position:CSToastPositionBottom
title:nil];
} else {
NSLog(@"event added failed --- %@",[error description]);
}
}];
}
Please suggest any idea.Thanks in advance