我有一個簡單的函數來請求訪問,以便在日曆中添加事件。如何模擬EKEventStore
typealias BoolCallback = (Bool) ->()
class SimpleCalendar {
let store: EKEventStore
init(store: EKEventStore = EKEventStore()) {
self.store = store
}
/// Request access to EventKit API for Calendar intergration
///
/// - Parameter callback: returns if access was recived or denied
func requestAccess(callback: @escaping BoolCallback) {
let status = EKEventStore.authorizationStatus(for: .event)
switch status {
case .authorized:
callback(true)
// case .notDetermined: //should ask for access
// case .denied, .restricted: //should open a ask permission view
default:
store.requestAccess(to: .event) { accessGranted, _ in
DispatchQueue.main.async {
callback(accessGranted)
}
}
}
}
}
有沒有辦法模擬EKEventStore
獲取狀態?
我也有一個簡單的函數來檢查日曆是否存在。
func doesCalendarExist(name: String) -> Bool {
let calendars = store.calendars(for: .event)
if calendars.contains(where: { $0.title == name }) {
return true
}
return false
}
有沒有辦法嘲笑存儲對象爲獲得store.calendars
感謝
我切換
let status = EKEventStore.authorizationStatus(for: .event)
到
let status = type(of: store).authorizationStatus(for: .event)
請檢查新的更新 –