ios - 无法在 Swift 4.2 中请求访问 IOS 日历的权限
<p><p>我已经尝试过请求允许将项目添加到 IOS 日历的早期示例。它们不适用于 Xcode 10.1 (Swift 4.2)。当我尝试编译代码时,出现错误。如果我注释掉以“EKEventstore.requestAccess”开头的行,代码将执行“.not.Determined”循环。</p>
<p>错误是“实例成员 'requestAccess' 不能用于类型 'EKEventStore';您的意思是使用此类型的值吗?”</p>
<p>谁能找到我的错误,以便 IOS 应用有权将事件添加到日历?</p>
<pre><code>func SOGetPermissionCalendarAccess() {
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Authorized")
case .denied:
print("Access denied")
case .notDetermined:
EKEventStore.requestAccess(to: .event, completion:
{ (granted: Bool, error: Error?) -> Void in
if granted {
print("Access granted")
} else {
print("Access denied")
}
})
print("Not Determined")
default:
print("Case Default")
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该如下创建事件存储实例,</p>
<pre><code>let eventStore = EKEventStore()
</code></pre>
<p>之后,您可以像下面这样提出权限请求,</p>
<pre><code>switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Authorized")
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{(granted: Bool, error: Error?) -> Void in
if granted {
print("Access granted")
} else {
print("Access denied")
}
})
print("Not Determined")
default:
print("Case Default")
}
</code></pre>
<p>请引用 <a href="https://developer.apple.com/documentation/eventkit/ekeventstore" rel="noreferrer noopener nofollow">link</a>了解更多信息。</p></p>
<p style="font-size: 20px;">关于ios - 无法在 Swift 4.2 中请求访问 IOS 日历的权限,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/53425093/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/53425093/
</a>
</p>
页:
[1]