如何在iOS中的Google日历中添加用户事件
问题描述:
我正在将Google日历集成到我的应用程序中。它已成功集成,现在我想将用户事件添加到Google日历。如果我在Google日历中添加用户事件,则该事件应该反映在jSon响应中。如何在iOS中的Google日历中添加用户事件
我有问题在json响应中获取用户事件。
-(void)updateCalendar
{
//NSString *calendarId = @"XXXX-fr62agepgso9n50s9nhv7c2g27inhqg6.apps.googleusercontent.com";
NSString *calendarId = @"[email protected]";
NSString *apiKey = @"XXX";
NSString *urlFormat = @"https://www.googleapis.com/calendar/v3/calendars/%@/events?key=%@&fields=items(id,start,summary,status)";
NSString *calendarUrl = [NSString stringWithFormat:urlFormat, calendarId, apiKey];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:calendarUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
{
[ADManagedObjectContext updateEvents:responseObject[@"items"]];
[self.refreshControl endRefreshing];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.refreshControl endRefreshing];
}];
}
答
首先从设备中检索所有日历。然后存储在NSArray中的所有日历通过使用此代码,
EKEventStore *eventStore = [[EKEventStore alloc] init];
caleandarsArray = [[NSArray alloc] init];
然后通过使用此代码的事件添加到选定的日历,
EKCalendar *calendar = [caleandarsArray objectAtIndex:1];
[events setCalendar:calendar];
NSError *err;
[eventStore saveEvent:events span:EKSpanThisEvent error:&err];
通过使用上面的代码,我们可以添加渴望日历事件。
OR
而不是使用谷歌API的,你应该使用EventKit(https://developer.apple.com/library/ios/documentation/EventKit/Reference/EKEventClassRef/index.html),很简单的东西,你能同步到用户想要的日历。
OR
@Dalm为了帮助我,如果你有任何想法PLZ。帮助我的任何机构 – satya
您是否尝试过https://developers.google.com/google-apps/calendar/quickstart/ios? – luc
@luc感谢您的回复。我跟着这个教程..https://github.com/theandrewdavis/ios-google-calendar ..但我想在谷歌日历添加事件..接下来相关的添加事件应该反映在我的JSON响应 – satya