【问题标题】:Can't request calendar event access (via EKEventStore) in Swift app for macOS无法在 macOS 的 Swift 应用程序中请求日历事件访问(通过 EKEventStore)
【发布时间】:2019-10-07 17:50:52
【问题描述】:

(我以前从未使用过 Swift 或 Xcode,所以这可能是一个愚蠢的问题)

为了隔离问题,我在 Xcode 11 中创建了一个完全空的“应用程序”,并将其放入 AppDelegate.swift

import Cocoa
import EventKit

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    private let eventStore = EKEventStore()

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        eventStore.requestAccess(to: .event) { granted, error in
            if granted {
                print("GOOD: Access granted")
            } else {
                print("BAD: Access denied")
            }
        }
    }
}

当我运行应用程序(通过 cmd+R)时,我立即看到它拒绝访问,而我没有机会批准访问:

Metal API Validation Enabled
BAD: Access denied

我做错了什么?如何获得它以允许我批准对日历活动的访问?

请注意,我注意到the docs 说:

要访问用户的日历数据,所有沙盒 macOS 应用都必须包含 com.apple.security.personal-information 密钥。

所以我在App_Name.entitlements 中进行了这样的更改,但没有帮助:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.personal-information</key>
    <true/>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-only</key>
    <true/>
</dict>
</plist>

【问题讨论】:

    标签: swift xcode macos eventkit


    【解决方案1】:

    已修复。我做错了两件事:

    1. 权利文件中的com.apple.security.personal-information 不正确。只需键入“日历”即可自动完成正确的任务。
    2. Info.plist 文件中,我需要“隐私 - 日历使用说明”来设置值。我在这里找到了:https://forums.developer.apple.com/thread/110825

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多