在MacOs

问题描述 投票:0回答:1

输入文件:

<?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.app-sandbox</key> <true/> <key>com.apple.security.files.user-selected.read-only</key> <true/> <key>com.apple.security.personal-information.calendars</key> <true/> </dict> </plist> Info.plist相关条目:

<key>NSCalendarsUsageDescription</key> <string>This app needs access to your calendar to display today's events</string> <key>NSCalendarsFullAccessUsageDescription</key> <string>This app needs full access to your calendar to display today's events</string> <key>NSCalendarsWriteOnlyAccessUsageDescription</key> <string>This app needs write access to your calendar to add and update events</string>

代码请求日历访问:

  @available(macOS 14.0, *)
  func requestAccess() {
      Task {
          // Try to access calendar events to trigger permission dialog
          let calendar = Calendar.current
          let startDate = calendar.startOfDay(for: Date())
          let endDate = calendar.date(byAdding: .day, value: 1, to: startDate)!
          let predicate = eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: nil)
          let _ = eventStore.events(matching: predicate)

          // Basic access request
          let basicPromise = DispatchGroup()
          basicPromise.enter()

          eventStore.requestAccess(to: .event) { (granted, error) in
              basicPromise.leave()
          }

          _ = basicPromise.wait(timeout: .now() + 5)

          // Open system settings
          if let url = URL(string: "x-apple.systempreferences:com.apple.settings.Privacy.Calendars") {
              NSWorkspace.shared.open(url)
          }

          // Check status
          let currentStatus = EKEventStore.authorizationStatus(for: .event)

          // If basic access is granted, request full access
          if currentStatus == .authorized || currentStatus == .fullAccess {
              do {
                  let _ = try await eventStore.requestFullAccessToEvents()
              } catch {
                  print("Full access error: \(error.localizedDescription)")
              }
          }
      }
  }
我也尝试了:

手动打开系统设置>隐私和安全>日历

使用基本requestAccess(to:.event)和完整访问请求requestfullaccesstoevents()方法(MACOS 14+)

在明确请求许可之前,force访问日历事件
请求之前和之后检查授权状态

    环境
  1. sonoma(14.x)
  2. XCode15
  3. App通过开发证书签署
  4. App是沙盒

预期的行为

    请求日历访问后,我的应用应出现在系统设置>隐私和安全>日历中,允许用户授予许可。
  • 实现行为
  • 该应用程序未出现在请求日历访问的应用程序列表中。从未显示“权限对话框”和EkeventStore。 .event)返回
  • 为什么我的应用程序不在隐私设置中显示以及如何解决此问题?
sandwer:

我设法解决了这个问题。事实证明,问题源于我的Info.plist

文件没有被正确管理为公认的

Info.plist

。具体来说,似乎系统无法正确注册必要的隐私密钥。

Solution:

I通过完全删除我的项目中的现有文件,然后通过Xcode的“文件> new> New> File ...”菜单(选择“属性列表”)添加新的,正确格式的文件来解决此问题。重新输入所需的

Info.plist

键,并确保正确设置权利的设置后,该应用现在如预期出现在隐私与安全>日历设置中。 本质上,问题可能是由于原始

Info.plist
swift macos calendar
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.