saveEvent返回“没有设置日历” [英] saveEvent returning "No calendar has been set"

查看:178
本文介绍了saveEvent返回“没有设置日历”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的应用程序中将事件保存到日历中。
我的代码适用于iOS 7,但在 iOS 6 上,它返回没有设置日历。

I am attempting to save an event into the calendar, from my application. My code works for iOS 7, but on iOS 6, it returns No calendar has been set.

应用程序提示用户在iOS 7上授予对日历的访问权限。
但iOS 6没有出现此类提示。虽然应用程序在设置 - >隐私 - >日历中被授予访问权限。

The application prompts for user to grant access to the calendar, on iOS 7. But no such prompt appears for iOS 6. Although the application is granted access in the Settings-> Privacy -> Calendar.

是的,我已经实现了 requestAccessToEntityType:completion:

这是我的代码段

EKEventStore *objStore = [[EKEventStore alloc]init];

if ([objStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
    // iOS 6 and later
    [objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (granted)
        {
            // code here for when the user allows your app to access the calendar
            EKEvent *calEvent = [EKEvent eventWithEventStore:objStore];
            calEvent.title = mstrTitleEvent;
            calEvent.startDate = self.dateToBeSet;
            calEvent.endDate = self.dateToBeSet;
            calEvent.calendar = objStore.defaultCalendarForNewEvents;

            EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet];
            [calEvent addAlarm:objAlarm];

            NSError *error;
            BOOL _bStatus = [objStore saveEvent:calEvent span:EKSpanThisEvent commit:YES error:&error];

            UIAlertView *alertV;

            if(_bStatus)
            {
                alertV = [[UIAlertView alloc]initWithTitle:@"Congratulations" message:@"Saved To Calendar" delegate:nil cancelButtonTitle:@"Right On!" otherButtonTitles:nil];
                [alertV show];
            }
            else
            {
                alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:[NSString stringWithFormat:@"Error saving to calendar, with error %@.",[error localizedDescription]] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
                [alertV show];
            }
        }
            else
        {
            // code here for when the user does NOT allow your app to access the calendar
            UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please grant access to the calendar, and try again later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alertV show];
        }
        });
    }];

}

推荐答案

很棒我在两个不同的设备上测试我的代码,一个工作正常,另一个工作不起作用。只是查看设置,其中一个没有工作有iCloud日历和提醒关闭,只需打开它们现在一切正常...这必须是一个错误

Amazing I am testing my code on two different devices, one it works fine and the other it will not work. Just looked in setting and the one with it not working has iCloud calendar and reminders turned off, just turn them on and it all works now... this has to be a bug

这篇关于saveEvent返回“没有设置日历”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆