Objective C - iCal 不在 iOS 9 中创建自定义日历和新事件

2024-01-09

这在 iOS 8 中完美运行。

但在 iOS 9 中创建问题。这里是代码:

self.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (granted) {

            // Create a new calendar.
            EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent
                                                          eventStore:self.eventManager.eventStore];

            // Set the calendar title.
            calendar.title = @"<APP name>";
            calendar.CGColor=APP_Blue_COLOR.CGColor;

            // Find the proper source type value.
            for (int i=0; i<self.eventManager.eventStore.sources.count; i++) {
                EKSource *source = (EKSource *)[self.eventManager.eventStore.sources objectAtIndex:i];
                EKSourceType currentSourceType = source.sourceType;

                if (currentSourceType == EKSourceTypeLocal) {
                    calendar.source = source;
                    break;
                }
            }


            // Save and commit the calendar.
            NSError *error;
            [self.eventManager.eventStore saveCalendar:calendar commit:YES error:&error];

            // If no error occurs then turn the editing mode off, store the new calendar identifier and reload the calendars.
            if (error == nil) {
                // Turn off the edit mode.
                // Store the calendar identifier.
                [self.eventManager saveCustomCalendarIdentifier:calendar.calendarIdentifier];self.eventManager.selectedCalendarIdentifier=calendar.calendarIdentifier;//chirag

            }
            else{
                // Display the error description to the debugger.
                NSLog(@"CREATE_CALENDER %@", [error localizedDescription]);
            }

        }
        else
        {

            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"Please give permission to access your iPhone calender." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
            [alert show];


        }

    }];

它给了我成功消息,但没有在 iPhone 日历中创建我的应用程序日历。

我虽然由于没有设置事件而没有显示它。所以我也尝试设置新事件。

但它在创建新事件时给了我以下代码和错误。

// Create a new event object.
    EKEvent *event = [EKEvent eventWithEventStore:self.eventManager.eventStore];

    // Set the event title.
    event.title = title;

    // Set its calendar.
    event.calendar = [self.eventManager.eventStore calendarWithIdentifier:self.eventManager.selectedCalendarIdentifier];

    // Set the start and end dates to the event.
    event.startDate = startDate;
    event.endDate = endDate;
 // Save and commit the event.
    NSError *error;
    if ([self.eventManager.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error]) {
        // Call the delegate method to notify the caller class (the ViewController class) that the event was saved.
        return true;
    }
    else{
        // An error occurred, so log the error description.
        NSLog(@"%@", [error localizedDescription]);
    return false;
    }

它在内部给出以下错误,但它会在 NSError 对象中返回:

Error getting shared calendar invitations for entity types 3 from daemon: Error Domain=EKCADErrorDomain Code=1014 "(null)"

问题是,当 iCloud 日历打开时,它会隐藏日历应用程序中本地创建的日历。要绕过此问题,解决方案是将新日历添加到 iCloud 源:

for (EKSource *source in self.eventStore.sources)
{
    if (source.sourceType == EKSourceTypeCalDAV && 
       [source.title isEqualToString:@"iCloud"]) //This is a patch.
    {
        localSource = source;
        break;
    }
}

if (localSource == nil)
{
    for (EKSource *source in self.eventStore.sources)
    {
        if (source.sourceType == EKSourceTypeLocal)
        {
            localSource = source;
            break;
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Objective C - iCal 不在 iOS 9 中创建自定义日历和新事件 的相关文章

随机推荐

  • Python 字符串到 unicode [重复]

    这个问题在这里已经有答案了 可能的重复 如何在 python 中将 ASCII 字符串视为 unicode 并对其中的转义字符进行转义 https stackoverflow com questions 267436 how do i tr
  • 如何使用 Python 将专辑封面嵌入到 MP3 中?

    我一直在使用 mutagen 来读取和写入 MP3 标签 但我希望能够将专辑封面直接嵌入到文件中 以下是如何使用 mutagen 将 example png 作为专辑封面添加到 example mp3 中 from mutagen mp3
  • C++ pow 函数 - 结果无效?

    为什么 dResult 的输出无效 环境 Visual Studio 2008 int tmain int argc TCHAR argv double dN 0 091023604111478473 double dD 0 1277777
  • jQuery - 禁用基于另一个字段选定值的输入字段

    我正在寻找一个可以执行此操作的 jQuery 插件 例如
  • thymeleaf - 将 th:each 与 th:href 结合起来

    我是 Thymeleaf 和 webdev 的新手 我正在尝试将 Thymeleaf 迭代 th each 与 URL 重写 th href 结合起来 a hello a 这会产生以下结果 其中lid 45 a href list l li
  • 在练习 TDD 的同时学习 OpenGL(单元测试)

    我已经开始了一个新的游戏项目 并决定为其学习和使用OpenGL 项目正在Windows和Linux上同时开发 同时 我也对测试驱动开发非常感兴趣 并且正在尽最大努力在任何实际代码之前编写单元测试来引导设计 然而 我认为我缺乏知识可能会绊倒我
  • 模拟两个方块碰撞以计算 PI 时的动画故障

    我在用pygame创建两个方块碰撞的模拟质量比为 100 次方 明确地说 这意味着较大块与较小块的比率可以是100 0 100 1 100 2等等 我在必要时添加了注释和文档字符串 以使逻辑易于理解 import pygame from c
  • 使用ServiceStack的Swagger Plugin,如何实现带有预设值列表的字符串字段

    我正在使用 ServiceStack 的新 Swagger 插件实现 Swagger API 文档 并尝试确定如何使用 容器 数据类型 我需要显示一个字符串字段 其中包含预定值列表和其他作为子对象列表的参数 除非我遗漏了一些东西 否则我相信
  • 在 Ubuntu 11.04 Natty 上进行 Android 调试

    我放置了一个名为 70 android rules 的文件 在 etc udev rules d with 子系统 USB SYSFS 22b8 22b8 模式 0666 但它仍然无法读取我的摩托罗拉 Atrix 是我做错了什么吗 我找到的
  • 将 QByteArray 附加到 QDataStream?

    我必须填充一个QByteArray具有不同的数据 所以我正在使用QDataStream QByteArray buffer QDataStream stream buffer QIODevice WriteOnly qint8 dataHe
  • 非聚集索引在 SQL Server 中的工作原理

    我有一个与数据库理论相关的问题 假设我们有一个包含 3 列的表 PersonID PersonName PersonAge 我们知道 当我们有一个一列的非聚集索引时 SQL Server会按照指定的列对表数据进行排序 并从中构建B 树 当我
  • 在 Python 中使用 readlines 是坏代码吗?

    我因使用 file readlines 的答案而被否决 批评者说使用 readlines 是垃圾代码 以及其他非常粗鲁的语句 有那么糟糕吗 我认为问题在于readlines 将整个文件加载到内存中 理论上 内存可能很大 就内存使用而言 惰性
  • 如何在谷歌浏览器扩展中创建套接字?

    我为谷歌浏览器创建了一个小 hello world 扩展http code google com chrome extensions getstarted html http code google com chrome extension
  • Twitter 的 OAuth 系统如何工作?

    我有一个演示脚本 可以让我使用我的应用程序进行授权并发回我的令牌 但这很令人困惑 我一直在 CURL 或 simpleXML 函数中使用用户名和密码来授权 API 调用 我不明白这与 oauth 有什么关系 我知道我将存储令牌 但是一旦我拥
  • Windows 上的 .NET Core 3.0 忽略 NO_PROXY

    我们正在尝试让代理功能在 Windows 上的 NET Core 3 0 或 3 1 应用程序中工作 我们发现 HTTPS PROXY 和 HTTP PROXY 变 量按预期进行识别和处理 但默认代理似乎不支持 NO PROXY 变 量 这
  • Git 通过 ngrok 隧道转发

    我的本地实例上有一个 git 存储库 我想从家庭网络外部访问它 我应该为此在本地实例上创建 git 服务器和 ssh 服务器吗 另外我应该使用 ngrok 建立隧道的端口是什么 任何意见都将不胜感激 如图所示第193期 https gith
  • Perl 中的反向 DNS 查找

    如何执行反向 DNS 查找 即如何在 Perl 中将 IP 地址解析为其 DNS 主机名 如果您需要更详细的 DNS 信息 请使用Net DNS http search cpan org olaf Net DNS 0 63 lib Net
  • 将 HBITMAP 绘制到分层窗口上。怎么了?

    大家好 美好的一天 我的最终目标是在屏幕上绘制一个包含 Alpha 的 PNG 文件 这意味着不是在自己的窗口中 而是在桌面上的某个位置 将 PNG 加载到 HBITMAP 的部分现在可以工作 以不同的方式进行测试 但我无法做到绘制它 包括
  • Java程序查找字符串数组中元音的长度和数量

    我需要从用户那里获取一个字符串并将其输出到一个表中 包括其单词数和元音数 但我不知道如何计算元音 我尝试了以下方法 import java util Scanner public class Array2 public static voi
  • Objective C - iCal 不在 iOS 9 中创建自定义日历和新事件

    这在 iOS 8 中完美运行 但在 iOS 9 中创建问题 这里是代码 self eventManager eventStore requestAccessToEntityType EKEntityTypeEvent completion