草庐IT

ios - EKEventStore - 该事件不属于该事件存储

coder 2024-01-19 原文

我根本无法保存我的提醒/事件。但是,我已被授予使用提醒的权限(我检查了设置)。我已经打印出错误,它说 That event does not belong to that event store. 这是我的代码;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.eventStore =[[EKEventStore alloc] init];
    self.eventStoreAccessGranted = NO;
    [self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
        self.eventStoreAccessGranted = granted;
        if (!granted) {
            NSLog(@"User has not granted permission");
        }
    }];

 }



- (IBAction)setAReminder:(id)sender {

    if (!self.eventStoreAccessGranted) {
        NSLog(@"Reminder is no");
        return;
    }
    NSLog(@"Reminder is YES");
    EKReminder * newReminder = [[EKReminder alloc] init];
    newReminder.title = @"Pick up the kids";
    newReminder.calendar = [self.eventStore defaultCalendarForNewReminders];


    NSDate *now = [NSDate date];
    NSDate *alarmDate = [now dateByAddingTimeInterval:120];
    EKAlarm * ourAlarm = [EKAlarm alarmWithAbsoluteDate:alarmDate];

    [newReminder addAlarm:ourAlarm];
    NSError *error = nil;

    [self.eventStore saveReminder:newReminder commit:YES error:&error];
    NSLog(@"Event %@",[error localizedDescription]);
}

对问题所在有什么建议吗?

最佳答案

我将我的代码更改为此并且它可以正常工作。

 -(IBAction)setAReminder:(id)sender {

    if (self.eventStore == nil)
    {
        self.eventStore = [[EKEventStore alloc]init];

        [self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {

        if (!granted)
            NSLog(@"Access to store not granted");
        }];
    }

    if (self.eventStore != nil)
        [self createReminder];

}

-(void)createReminder
{
    EKReminder *reminder = [EKReminder
                        reminderWithEventStore:self.eventStore];

    reminder.title = @"Test";

    reminder.calendar = [_eventStore defaultCalendarForNewReminders];

    NSDate *date = [NSDate date];

    EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:[date dateByAddingTimeInterval:120]];

    [reminder addAlarm:alarm];

     NSError *error = nil;

    [_eventStore saveReminder:reminder commit:YES error:&error];

    if (error)
    NSLog(@"error = %@", error);

}

关于ios - EKEventStore - 该事件不属于该事件存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656252/

有关ios - EKEventStore - 该事件不属于该事件存储的更多相关文章

  1. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  2. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  3. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  4. ruby-on-rails - 事件管理员日期过滤器日期格式自定义 - 2

    是否有简单的方法来更改默认ISO格式(yyyy-mm-dd)的ActiveAdmin日期过滤器显示格式? 最佳答案 您可以像这样为日期选择器提供额外的选项,而不是覆盖js:=f.input:my_date,as::datepicker,datepicker_options:{dateFormat:"mm/dd/yy"} 关于ruby-on-rails-事件管理员日期过滤器日期格式自定义,我们在StackOverflow上找到一个类似的问题: https://s

  5. ruby - Rack:如何将 URL 存储为变量? - 2

    我正在编写一个简单的静态Rack应用程序。查看下面的config.ru代码:useRack::Static,:urls=>["/elements","/img","/pages","/users","/css","/js"],:root=>"archive"map'/'dorunProc.new{|env|[200,{'Content-Type'=>'text/html','Cache-Control'=>'public,max-age=6400'},File.open('archive/splash.html',File::RDONLY)]}endmap'/pages/search.

  6. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  7. ruby-on-rails - 事件记录 : Select max of limit - 2

    我正在尝试将以下SQL查询转换为ActiveRecord,它正在融化我的大脑。deletefromtablewhereid有什么想法吗?我想做的是限制表中的行数。所以,我想删除少于最近10个条目的所有内容。编辑:通过结合以下几个答案找到了解决方案。Temperature.where('id这给我留下了最新的10个条目。 最佳答案 从您的SQL来看,您似乎想要从表中删除前10条记录。我相信到目前为止的大多数答案都会如此。这里有两个额外的选择:基于MurifoX的版本:Table.where(:id=>Table.order(:id).

  8. ruby-on-rails - 为什么在 Rails 5.1.1 中删除了 session 存储初始化程序 - 2

    我去了这个website查看Rails5.0.0和Rails5.1.1之间的区别为什么5.1.1不再包含:config/initializers/session_store.rb?谢谢 最佳答案 这是删除它的提交:Setupdefaultsessionstoreinternally,nolongerthroughanapplicationinitializer总而言之,新应用没有该初始化器,session存储默认设置为cookie存储。即与在该初始值设定项的生成版本中指定的值相同。 关于

  9. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  10. ruby-on-rails - 事件管理员和自定义方法 - 2

    这是我在ActiveAdmin中的自定义页面ActiveAdmin.register_page"Settings"doaction_itemdolink_to('Importprojects','settings/importprojects')endcontentdopara"Text"endcontrollerdodefimportprojectssystem"rakedataspider:import_projects_ninja"para"OK"endendend我想做的是,当我单击“导入项目”按钮时,我想在Controller中执行rake任务。但是我无法访问该方法。可能是什

随机推荐