加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何将事件推送到iPhone日历

发布时间:2020-12-15 08:02:15 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的应用程序( Windows桌面应用程序和Web应用程序)与移动日历集成. 我的应用程序应该是 将新事件推送到移动日历 从移动日历中获取事件 到目前为止,我设法与Google日历集成(非常简单,simple library OAuth) 现在我想对iCloud日历做同样的事情,但
我正在尝试将我的应用程序( Windows桌面应用程序和Web应用程序)与移动日历集成.

我的应用程序应该是

>将新事件推送到移动日历
>从移动日历中获取事件

到目前为止,我设法与Google日历集成(非常简单,simple library OAuth)

现在我想对iCloud日历做同样的事情,但事情并非如此简单.

>在iCould设置中,我可以公开日历.我可以获取事件(作为iCalendar文件),但我无法推送事件.
>找不到任何用于iCould日历集成的严肃库.我试了CalDav.Client,但需要提供CalDAV服务器网址.根据this应该看起来像“https://pXX-caldav.icloud.com/USER_ID/calendars/CALENDAR_ID.我不知道USER_ID和CALENDAR_ID是什么以及在哪里找到它们.

有任何想法吗?

PS

有一个解决方法.我可以要求用户创建Google帐户以及日历并将其用作代理.将iPhone与Google日历集成,并形成另一个站点,将我的应用程序与Google日历集成.它可以工作,但配置对用户来说有点乏味.

编辑

我尝试按照@ hnh的说明并以这种方式发现CalDAV:

PROPFIND https://p42-caldav.icloud.com/ HTTP/1.1
Depth: 0
Prefer: return-minimal
Content-Type: application/xml; charset=utf-8
Host: p42-caldav.icloud.com
Content-Length: 102

<d:propfind xmlns:d="DAV:">
  <d:prop>
     <d:current-user-principal />
  </d:prop>
</d:propfind>

结果是401:

HTTP/1.1 401 Unauthorized
Content-Type: text/html;charset=utf-8
WWW-Authenticate: x-mobileme-authtoken realm="MMCalDav"
WWW-Authenticate: basic realm="MMCalDav"
Server: iCloudCalendarServer 15G33
Date: Tue,26 Jan 2016 12:46:14 GMT
X-Responding-Server: mr26p42ic-ztdg05101801 17 a63660a6f7d1a25b5a7ed66dab0da843
X-Transaction-Id: c8dc19d4-c42a-11e5-8381-008cfaeb448c
Content-Length: 141
Strict-Transport-Security: max-age=31536000; includeSubDomains

<html><head><title>Unauthorized</title></head><body><h1>Unauthorized</h1><p>You are not authorized to access this resource.</p></body></html>

编辑2

根据进一步的说明,我设法进行了身份验证,但文章中的请求仍然存在问题:

对于:

<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
  <d:prop>
     <d:displayname />
     <cs:getctag />
  </d:prop>
</d:propfind>

我得到:(ctag not found,displayName的值为“tmp” – 我不认识)

<?xml version='1.0' encoding='UTF-8'?>
<multistatus xmlns='DAV:'>
  <response>
    <href>/</href>
    <propstat>
      <prop>
        <displayname>tmp</displayname>
      </prop>
      <status>HTTP/1.1 200 OK</status>
    </propstat>
    <propstat>
      <prop>
        <getctag xmlns='http://calendarserver.org/ns/'/>
      </prop>
      <status>HTTP/1.1 404 Not Found</status>
    </propstat>
  </response>
</multistatus>

为此:

<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
    <d:prop>
        <d:getetag />
        <c:calendar-data />
    </d:prop>
    <c:filter>
        <c:comp-filter name="VCALENDAR" />
    </c:filter>
</c:calendar-query>

我得到400 Bad Request

解决方法

这是一个很好的介绍: Building a CalDAV client.它还描述了日历发现过程的工作原理(如何查找日历主页URL).

许多CalDAV服务器不支持OAuth,您通常需要询问用户登录/密码.

似乎没有适用于CalDAV的.NET库.您可以在此处找到实施列表:http://caldav.calconnect.org/implementations/librariestools.html.

总结:可能不像你用Google做的那么简单,但也不是超级硬.一旦你拥有它,你可以连接到许多不同的服务器,因为CalDAV是一个标准…(包括谷歌,你也可以连接到CalDAV).

编辑问题后更新:

401是一般的HTTP响应.这意味着您需要提供凭据才能继续请求.客户端通常会提示用户输入登录名/密码,然后重新运行该请求.基本身份验证在Wikipedia article on Basic auth中有详细描述.

另一个错误是使用p42-caldav.icloud.com作为入口点URL.使用caldav.icloud.com,因为您不知道用户所在的分区.您需要使用Building a CalDAV client中所述的发现过程来查找托管用户日历的实际URL.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读