ios - iOS 10 及更高版本中的 EKEventStore requestAccessToEntityType 崩溃应用程序

标签 ios swift calendar ekevent ekeventstore

我有一个应用程序,我必须在其中添加默认日历中的事件,该日历在 iOS 10 之前运行良好。现在在 iOS 10 中它不授予访问权限。我已将 use legacy swift language version 设置为 yes。我的代码是

let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(EKEntityType.Event) {
   case .Authorized:
            //access
   case .Denied:
            print("Access denied")
   case .NotDetermined:
       eventStore.requestAccessToEntityType(EKEntityType.Event, completion:
                {[weak self] (granted: Bool, error: NSError?) -> Void in
                    if granted {
                        //access
                    } else {
                        print("Access denied")
                    }
                })
   default:
            print("Case Default")
  }

虽然调试我的应用程序在 Xcode 8 中的 eventStore.requestAccessToEntityType 处崩溃。

Screenshot of debug

我的应用已上线,我需要解决它。任何帮助都是适当的。提前致谢。

最佳答案

在iOS 10 build上,需要在Info.plist上设置权限提醒的描述信息

Important: An iOS app linked on or after iOS 10.0 must include in its Info.plist file the usage description keys for the types of data it needs to access or it will crash. To access Reminders and Calendar data specifically, it must include NSRemindersUsageDescription and NSCalendarsUsageDescription, respectively.

来自 Apple Docs

关于ios - iOS 10 及更高版本中的 EKEventStore requestAccessToEntityType 崩溃应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39918076/

相关文章:

ios - Firebase 存储图像缓存不更新 SWIFT

php - 由于位数不同,sql 表中的时间查询不正确

Python:从 `datetime.datetime` 转换为 `time.time`

ios - 两个 NavigationBar 显示

android - 基于接近度的遥控 key 安全设备,带蓝牙 : how it works

xcode - 找不到 Storyboard错误

ios - 如何在 Swift 中显示 SDWebimage 背景颜色

javascript - 未捕获的类型错误 : Cannot read property 'regional' of undefined?

ios - 接入点 :Error Domain = NSCocoaErrorDomain Code=3840

ios - AWS Cognito 身份验证凭证 IOS Swift 2.3 - 3(集成用户池和身份池)