小编How*_*tis的帖子

无法请求访问Swift 4.2中的IOS日历的权限

我已经尝试了要求向IOS日历添加项目的权限的早期示例。它们不适用于Xcode 10.1(Swift 4.2)。当我尝试编译代码时,出现错误。如果我注释掉以“ EKEventstore.requestAccess”开头的行,则代码将执行“ .not.Determined”循环。

错误是“实例成员'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")
        }

}
Run Code Online (Sandbox Code Playgroud)

iphone ios swift4 ios12 xcode10

4
推荐指数
1
解决办法
1163
查看次数

标签 统计

ios ×1

ios12 ×1

iphone ×1

swift4 ×1

xcode10 ×1