我尝试了早期的例子,请求在iOS日历中添加项目的权限。但是它们与Xcode 10.1(Swift 4.2)不兼容。当我尝试编译代码时,会出现错误。如果我注释掉以“EKEventstore.requestAccess”开头的行,则该代码会执行“.not.Determined”循环。
错误信息为:“实例成员‘requestAccess’无法在类型‘EKEventStore’上使用;你是否意味着要使用此类型的值?”
请问有人能找到我的错误吗,以便iOS应用程序可以获得向日历添加事件的权限?
错误信息为:“实例成员‘requestAccess’无法在类型‘EKEventStore’上使用;你是否意味着要使用此类型的值?”
请问有人能找到我的错误吗,以便iOS应用程序可以获得向日历添加事件的权限?
func SOGetPermissionCalendarAccess() {
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Authorized")
case .denied:
print("Access denied")
case .notDetermined:
EKEventStore.requestAccess(to: .event, completion:
{[weak self] (granted: Bool, error: Error?) -> Void in
if granted {
print("Access granted")
} else {
print("Access denied")
}
})
print("Not Determined")
default:
print("Case Default")
}
}