iPhone:如何检测 EKEvent 实例是否可以修改?

发布于 2024-10-08 08:19:10 字数 353 浏览 3 评论 0原文

在 iPhone 上使用 EventKit 时,我注意到有些事件可能存在且无法修改。到目前为止,我遇到的例子是与 CalDAV 同步的生日和事件。当您在 iPhone 上的标准内置日历应用程序中查看事件的详细信息时,右上角的“编辑”按钮在这些情况下不可见,而在查看“正常”事件时则可见。

我到处搜索,阅读所有文档,但我根本找不到任何告诉我如何检测这种行为的内容!我只能事后检测它:

  1. 编辑事件的标题
  2. 将其保存到事件存储
  3. 检查事件的标题,如果没有更改,则不可编辑!

我正在寻找一种可以提前检测事件的不可编辑行为的方法。我知道这是可能的,因为我已经看到其他日历应用程序正确地实现了这一点。

While working with the EventKit on iPhone I noticed that some events can exist which cannot be modified. Examples I encountered so far are birthdays and events synced with CalDAV. When you view the event's details in the standard built-in calendar app on iPhone the "Edit" button in the top-right corner is not visible in these cases, where it would be visible when viewing "normal" events.

I've searched everywhere, read all documentation there is but I simply can't find anything that tells me how to detect this behavior! I can only detect it afterwards:

  1. edit an event's title
  2. save it to the event store
  3. check the event's title, if it has not changed it is not editable!

I am looking for a way that I can detect the non-editable behavior of an event beforehand. I know this is possible because I've seen other calendar apps implement this correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

笔落惊风雨 2024-10-15 08:19:10

好吧,看来 SDK 没有为我提供任何可用于检查 EKEvent 是否为只读的内容。我通过创建一个类别来创建一个解决方法,该类别向所有 EKEvent 实例添加“isReadOnly”方法。

EKEvent+ReadOnlyCheck.h

@interface EKEvent(ReadOnlyCheck)
- (BOOL) isReadOnly;
@end`

EKEvent+ReadOnlyCheck.m

#import "EKEvent+ReadOnlyCheck.h"

@implementation EKEvent(ReadOnlyCheck)

- (BOOL) isReadOnly {
    BOOL readOnly;
    NSString *originalTitle = [self.title retain];
    NSString *someRandomTitle = [NSString stringWithFormat:@"%i", arc4random()];

    self.title = someRandomTitle;
    readOnly = [originalTitle isEqualToString:self.title];
    self.title = originalTitle;
    [originalTitle release];

    return readOnly;
}
@end

当上述文件就位后,我可以简单地对我选择的 EKEvent 调用 isReadOnly

#import "EKEvent+ReadOnlyCheck.h"
...
if ([event isReadOnly]) {
    // Do your thing
}
...

Ok it appears as if the SDK doesn't provide me with anything I can use to check if an EKEvent is read-only. I created a workaround by creating a category that adds an "isReadOnly" method to all EKEvent instances.

EKEvent+ReadOnlyCheck.h

@interface EKEvent(ReadOnlyCheck)
- (BOOL) isReadOnly;
@end`

EKEvent+ReadOnlyCheck.m

#import "EKEvent+ReadOnlyCheck.h"

@implementation EKEvent(ReadOnlyCheck)

- (BOOL) isReadOnly {
    BOOL readOnly;
    NSString *originalTitle = [self.title retain];
    NSString *someRandomTitle = [NSString stringWithFormat:@"%i", arc4random()];

    self.title = someRandomTitle;
    readOnly = [originalTitle isEqualToString:self.title];
    self.title = originalTitle;
    [originalTitle release];

    return readOnly;
}
@end

When the above files are in place I can simply call isReadOnly on the EKEvent of my choice.

#import "EKEvent+ReadOnlyCheck.h"
...
if ([event isReadOnly]) {
    // Do your thing
}
...
温柔嚣张 2024-10-15 08:19:10

我还没有使用过 Event Kit,但从文档来看,可编辑性似乎是日历的属性,而不是事件的属性。 event.calendar 获取事件的日历,calendar.allowsContentModifications 告诉您日历是只读还是读写。

I haven't worked with Event Kit yet, but from the documentation it seems that editability is a property of a calendar, not of an event. event.calendar gets you the event's calendar, and calendar.allowsContentModifications tells you if the calendar is read-only or read-write.

叫嚣ゝ 2024-10-15 08:19:10

在显示视图之前尝试 EKEventViewController 的 allowedEditing 属性。

try allowsEditing property of EKEventViewController before displaying the view.

笑叹一世浮沉 2024-10-15 08:19:10

是的。这是可能的。代码如下所示:
尝试通过记录我与可编辑/不可编辑事件一起使用的对象的输出来与代码相关,您将了解其工作原理:)

EKEventViewController *controller = [[EKEventViewController alloc] init];
controller.event = myEvent; /*myEvent is of type EKEvent*/          
if(controller.navigationItem.leftBarButtonItem != NULL)
{
    /*Event is Editable, Your code here*/
}

Yes. It is possible. The code would look like following :
Try relating to code by logging the output of objects I use with editable/non editable events and you will understand the working:)

EKEventViewController *controller = [[EKEventViewController alloc] init];
controller.event = myEvent; /*myEvent is of type EKEvent*/          
if(controller.navigationItem.leftBarButtonItem != NULL)
{
    /*Event is Editable, Your code here*/
}
葬花如无物 2024-10-15 08:19:10

我认为为 EKEvent 添加此类别方法可以处理事件不可编辑的所有情况:

- (BOOL)isReadOnly {
    if (self.calendar.allowsContentModifications == NO) return YES;
    if (self.organizer && [self.organizer isCurrentUser] == NO) return YES;
    return NO;
}

I think adding this category method for EKEvent handles all cases where events are not editable:

- (BOOL)isReadOnly {
    if (self.calendar.allowsContentModifications == NO) return YES;
    if (self.organizer && [self.organizer isCurrentUser] == NO) return YES;
    return NO;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文