【问题标题】:EKEventStore: 'initWithAccessToEntityTypes' is unavailable: not available on iOSEKEventStore:“initWithAccessToEntityTypes”不可用:在 iOS 上不可用
【发布时间】:2020-06-04 03:17:24
【问题描述】:

我正在尝试设置一个EKEventStore 以(在他们的许可下)在 iOS 应用中显示用户的日历活动。

我遇到的关于如何初始化 EKEventStore 实例 (1.Accessing the Event Store; 2.Reading and Writing Calendar Events) 的前几页 Apple 文档是这样说的:

EKEventStore *eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];

但是,在使用最新 Xcode(版本 11.3)和“单页应用程序”模板创建的新 iOS 应用程序中,将上述代码行添加到 ViewController.m 的 viewDidLoad 方法中,Xcode 给出了这个错误:

'initWithAccessToEntityTypes' is unavailable: not available on iOS

在 iOS 应用中初始化 EKEventStore 的正确方法是什么?

【问题讨论】:

    标签: ios objective-c eventkit


    【解决方案1】:

    文章EKEventStore暗示在iOS上,你可以在iOS上使用默认的init方法:

    在 macOS 中,使用 initWithAccessToEntityTypes: 代替默认的 init 方法。可接受的实体类型是事件的 EKEntityMaskEvent 和提醒的 EKEntityMaskReminder。

    我尝试在我的应用的 ViewController.m 中这样做:

    #import <EventKit/EventKit.h>
    
    // ...
    
    - (void)viewDidLoad 
    {
        EKEventStore *eventStore = [[EKEventStore alloc] init];
    
        // ...
    }
    

    这在我的 iOS 应用中对我来说效果很好;我能够继续使用eventStore 成功检索日历事件(在用户在运行时授予权限之后)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      相关资源
      最近更新 更多