向日历iOS添加条目-Xamarin

向日历iOS添加条目-Xamarin,ios,xamarin,Ios,Xamarin,我正在尝试从iOS上的应用程序在日历中创建一个新条目。 我有以下代码: public void AddEvent(String eventTitle, String eventDescription, DatePicker eventBegin, String repeat) { RequestAccess(); EKEventStore eventStore = new EKEventStore(); Foundation.NS

我正在尝试从iOS上的应用程序在日历中创建一个新条目。 我有以下代码:

    public void AddEvent(String eventTitle, String eventDescription, DatePicker eventBegin, String repeat)
    {
        RequestAccess();
        EKEventStore eventStore = new EKEventStore();

        Foundation.NSDate nsDate = (NSDate)eventBegin.Date;
        DateTime dateTime = (DateTime)nsDate;
        Foundation.NSError ex = null;

        var StartDate = nsDate.ToString();

        try
        {
            EKEvent newEvent = EKEvent.FromStore(eventStore);
            newEvent.StartDate = nsDate;
            newEvent.EndDate = nsDate;
            newEvent.Title = eventTitle;
            newEvent.Notes = eventDescription;
            newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;
            eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out ex);
        } catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
但是当我调用这个函数时,我的应用程序正在关闭,我已经调试了它,并且没有引发异常。 应用程序输出如下所示:

Thread started:  #11
2020-10-07 12:06:20.141477+0300 MasseyFeeds.iOS[1692:95841] [EventKit] Error getting default calendar for new events: Error Domain=EKCADErrorDomain Code=1013 "(null)"
2020-10-07 12:06:20.141647+0300 MasseyFeeds.iOS[1692:95841] [EventKit] No object ID provided.  Will not find out if the object exists.
Thread started:  #12
2020-10-07 12:06:29.248546+0300 MasseyFeeds.iOS[1692:95841] [Common] _BSMachError: port 14d03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2020-10-07 12:06:29.249561+0300 MasseyFeeds.iOS[1692:95841] [Common] _BSMachError: port 14d03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
知道我为什么会得到这个吗

谢谢

Error-Domain=EKCADErrorDomain-code=1013

您必须请求用户批准访问日历

如果您的应用以前从未请求过访问,则在尝试获取或创建事件或提醒之前,您必须请求访问它们。如果在使用此方法提示用户访问之前请求数据,则需要使用reset方法重置事件存储,以便在用户授予访问权限后开始接收数据

  • 苹果文档:

  • Xamarin文件,备注部分:

Xamarin文档中的示例:
Error-Domain=EKCADErrorDomain-code=1013

您必须请求用户批准访问日历

如果您的应用以前从未请求过访问,则在尝试获取或创建事件或提醒之前,您必须请求访问它们。如果在使用此方法提示用户访问之前请求数据,则需要使用reset方法重置事件存储,以便在用户授予访问权限后开始接收数据

  • 苹果文档:

  • Xamarin文件,备注部分:

Xamarin文档中的示例:
谢谢你的回复!我试过这种方法,但没有效果
grated
为true,我的代码被访问,但没有任何操作。我明白了:
2020-10-08 12:25:15.790487+0300 MasseyFeeds.iOS[3488:223909]SectaskloadAuthorities失败错误=22 cs_flags=200,pid=3488
@ClaudiuL93大量的
SectaskloadAuthorities
error=22信息,谷歌/bing谢谢你的回复!我试过这种方法,但没有效果
grated
为true,我的代码被访问,但没有任何操作。我明白了:
2020-10-08 12:25:15.790487+0300 MasseyFeeds.iOS[3488:223909]SectaskloadAuthorities失败错误=22 cs\u flags=200,pid=3488
@ClaudiuL93大量的
SectaskloadAuthorities
error=22信息,谷歌/bing it
App.Current.EventStore.RequestAccess (EKEntityType.Event, 
    (bool granted, NSError e) => {
        if (granted)
            //do something here
        else
            new UIAlertView ( "Access Denied", 
"User Denied Access to Calendar Data", null,
"ok", null).Show ();
        } );