forked from lemberg/ios-permissions-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarPermission.swift
32 lines (27 loc) · 938 Bytes
/
CalendarPermission.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// CalendarPermission.swift
//
// Created by Les Melnychuk on 2/19/16.
// Copyright © 2016 LembergSolutions. All rights reserved.
//
import UIKit
import EventKit
final class CalendarPermission: PermissonConfiguration {
func restrictedAlertMessage() -> String {
return "This app does not have access to your calendar"
}
func checkStatus() -> PermissonStatus {
let statusInt = EKEventStore.authorizationStatusForEntityType(EKEntityType.Event).rawValue
guard let status = PermissonStatus(rawValue: statusInt) where (0...3) ~= statusInt else {
assertionFailure("Impossible status")
return .NotDetermined
}
return status
}
func requestStatus(requestGranted: (successRequestResult: Bool) -> Void) {
EKEventStore().requestAccessToEntityType(EKEntityType.Event) {
(accessGranted: Bool, error: NSError?) in
requestGranted(successRequestResult: accessGranted)
}
}
}