我的应用如何获取用户 iPhone 上的日历列表
我正在编写一个 iPhone 应用程序,它将使用 EventKit 框架在用户的日历中创建新事件。这部分工作得很好(除了它处理时区的奇怪方式——但这是另一个问题)。我不知道如何获取用户日历的列表,以便他们可以选择将事件添加到哪个日历。我知道它是一个 EKCalendar 对象,但文档没有显示任何获取整个集合的方法。
预先感谢,
马克
I'm writing an iPhone app that will use the EventKit framework to create new events in the user's Calendar. That part works pretty well (except for the wonky way it handles the timezone -- but that's another issue). What I can't figure out is how to get a list of the user's calendars so that they can choose which calendar to add the event to. I know that its an EKCalendar object but the docs don't show any way to get the whole collection.
Thanks in advance,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
搜索文档会发现
EKEventStore
具有calendars
属性的类。我的猜测是,您会执行以下操作:
编辑:从 iOS 6 开始,您需要指定是否要检索提醒日历或事件日历:
Searching through the documentation reveals an
EKEventStore
class that has acalendars
property.My guess is that you'd do something like:
EDIT: As of iOS 6, you need to specify whether you want to retrieve calendars of reminders or calendars of events:
我用来获取日历名称和类型的可用 NSDictionary 的代码如下:
The code I used to get a useable NSDictionary of calendar names and types is like this:
我得到了日历列表,问题是我没有得到用户可显示的列表。对于所有这些,calendar.title 属性均为 null;我也没有看到任何类型的 id 属性。
->更新:它现在对我有用。我犯的错误是将 eventStore 对象放入临时变量中,然后获取日历列表,然后释放 eventStore。好吧,如果你这样做了,你所有的日历也会消失。在某些 iOS 框架中,Containment 并不是严格面向对象的,这就是一个例子。也就是说,日历对象依赖于事件存储,它不是它自己的独立实体。
无论如何 - 上面的解决方案很好!
I get the list of calendars OK - the problem is I don't get a user-displayable list. The calendar.title property is null for all of them; I don't see any kind of id property either.
-> Update: It works now for me. The mistake I had made was to put the eventStore object in a temporary variable, then get the list of calendars, then release the eventStore. Well if you do that all your calendars go away too. Containment is not strictly object oriented in some of the iOS frameworks, and this is an example of that. That is, the calendar object is dependent on the event store, it's not its own, separate entity.
Anyway -the solution above is fine!