Skip to content

Commit a59f629

Browse files
lammertwnathanhosselton
authored andcommitted
Add EventKit Category
1 parent 5c36d05 commit a59f629

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

Diff for: Categories/EventKit/EKEventStore+Promise.swift

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// EKEventStore+Promise.swift
3+
// PromiseKit
4+
//
5+
// Created by Lammert Westerhoff on 16/02/16.
6+
// Copyright © 2016 Max Howell. All rights reserved.
7+
//
8+
9+
import CoreFoundation
10+
import Foundation.NSError
11+
import EventKit
12+
13+
#if !COCOAPODS
14+
import PromiseKit
15+
#endif
16+
17+
public enum EventKitError: ErrorType {
18+
case Restricted
19+
case Denied
20+
21+
public var localizedDescription: String {
22+
switch self {
23+
case .Restricted:
24+
return "A head of family must grant calendar access."
25+
case .Denied:
26+
return "Calendar access has been denied."
27+
}
28+
}
29+
}
30+
31+
/**
32+
Requests access to the event store.
33+
34+
To import `EKEventStore`:
35+
36+
use_frameworks!
37+
pod "PromiseKit/EventKit"
38+
39+
And then in your sources:
40+
41+
import PromiseKit
42+
43+
@return A promise that fulfills with the EKEventStore.
44+
*/
45+
public func EKEventStoreRequestAccess() -> Promise<(EKEventStore)> {
46+
let eventStore = EKEventStore()
47+
return Promise { fulfill, reject in
48+
49+
let authorization = EKEventStore.authorizationStatusForEntityType(EKEntityType.Event)
50+
switch authorization {
51+
case .Authorized:
52+
fulfill(eventStore)
53+
case .Denied:
54+
reject(EventKitError.Denied)
55+
case .Restricted:
56+
reject(EventKitError.Restricted)
57+
case .NotDetermined:
58+
eventStore.requestAccessToEntityType(EKEntityType.Event) { granted, error in
59+
if granted {
60+
fulfill(eventStore)
61+
} else {
62+
reject(EventKitError.Denied)
63+
}
64+
}
65+
}
66+
}
67+
}

Diff for: PromiseKit.podspec

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Pod::Spec.new do |s|
8080
ss.dependency 'PromiseKit/CorePromise'
8181
ss.frameworks = 'CoreLocation'
8282
end
83+
84+
s.subspec 'EventKit' do |ss|
85+
ss.ios.source_files = 'Categories/EventKit/*'
86+
ss.dependency 'PromiseKit/CorePromise'
87+
ss.ios.frameworks = 'EventKit'
88+
end
8389

8490
s.subspec 'Foundation' do |ss|
8591
ss.ios.source_files = Dir['Categories/Foundation/*'] - Dir['Categories/Foundation/NSTask*']

Diff for: PromiseKit.xcodeproj/project.pbxproj

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
431B66E41CAC8022006CFC50 /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6373805B1B3E1C8E0060B7CA /* Bolts.framework */; };
11+
2F814F131C73A8C800ABF4D1 /* EKEventStore+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F814F111C73782100ABF4D1 /* EKEventStore+Promise.swift */; };
1112
43EF78B41C5AB88600BCD8FB /* after.m in Sources */ = {isa = PBXBuildFile; fileRef = 63A60E1F1AFD795B00C4E692 /* after.m */; };
1213
43EF78B51C5AB88600BCD8FB /* after.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63075EBD1AD0EDB3002C46A0 /* after.swift */; };
1314
43EF78B61C5AB88600BCD8FB /* AnyPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = 63A157711ABB59D00002A421 /* AnyPromise.m */; };
@@ -84,7 +85,6 @@
8485
635D0D761ADDA2EA00CC0406 /* AnyPromise.test.m in Sources */ = {isa = PBXBuildFile; fileRef = 635D0D741ADDA2C100CC0406 /* AnyPromise.test.m */; };
8586
635D0D7B1ADDB11400CC0406 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635D0D7A1ADDB11400CC0406 /* Error.swift */; };
8687
635D0D7C1ADDB11400CC0406 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635D0D7A1ADDB11400CC0406 /* Error.swift */; };
87-
6373805E1B3E1C9D0060B7CA /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6373805D1B3E1C9D0060B7CA /* Bolts.framework */; };
8888
63772C9C1AF09B8A00ED2F59 /* ErrorUnhandler.test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63772C9B1AF09B8A00ED2F59 /* ErrorUnhandler.test.swift */; };
8989
6384F5FA1B41F3EE00CB9679 /* PromiseKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 63F803CC1AB89A0F00E4DEE1 /* PromiseKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9090
63877E721B792C680042195F /* TestNSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63877E711B792C680042195F /* TestNSURLSession.swift */; };
@@ -358,6 +358,7 @@
358358
/* End PBXCopyFilesBuildPhase section */
359359

360360
/* Begin PBXFileReference section */
361+
2F814F111C73782100ABF4D1 /* EKEventStore+Promise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "EKEventStore+Promise.swift"; sourceTree = "<group>"; };
361362
43EF78A61C5AA12B00BCD8FB /* PromiseKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PromiseKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
362363
6302AC8E1AEF42F2001F0069 /* ACAccountStore+AnyPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ACAccountStore+AnyPromise.h"; sourceTree = "<group>"; };
363364
6302AC8F1AEF42F2001F0069 /* ACAccountStore+AnyPromise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ACAccountStore+AnyPromise.m"; sourceTree = "<group>"; };
@@ -600,6 +601,14 @@
600601
/* End PBXFrameworksBuildPhase section */
601602

602603
/* Begin PBXGroup section */
604+
2F814F101C73779800ABF4D1 /* EventKit */ = {
605+
isa = PBXGroup;
606+
children = (
607+
2F814F111C73782100ABF4D1 /* EKEventStore+Promise.swift */,
608+
);
609+
path = EventKit;
610+
sourceTree = "<group>";
611+
};
603612
43EA5FF21C5AC38C000BAEA7 /* tvOS */ = {
604613
isa = PBXGroup;
605614
children = (
@@ -913,6 +922,7 @@
913922
63D1BA9D1B256DE500435BF3 /* Bolts */,
914923
6302AC991AEF42F2001F0069 /* CloudKit */,
915924
6302ACA01AEF42F2001F0069 /* CoreLocation */,
925+
2F814F101C73779800ABF4D1 /* EventKit */,
916926
6302ACA71AEF42F2001F0069 /* Foundation */,
917927
6302ACB21AEF42F2001F0069 /* MapKit */,
918928
6302ACB91AEF42F2001F0069 /* MessageUI */,
@@ -1559,6 +1569,7 @@
15591569
638AF9561B62B7230045C3E8 /* TestMapKit.swift in Sources */,
15601570
638AF9571B62B7230045C3E8 /* TestQuartzCore.m in Sources */,
15611571
638AF95A1B62B7230045C3E8 /* TestSocial.m in Sources */,
1572+
2F814F131C73A8C800ABF4D1 /* EKEventStore+Promise.swift in Sources */,
15621573
638AF95B1B62B7230045C3E8 /* TestSocial.swift in Sources */,
15631574
638AF95C1B62B7230045C3E8 /* TestStoreKit.m in Sources */,
15641575
638AF95D1B62B7230045C3E8 /* TestStoreKit.swift in Sources */,

0 commit comments

Comments
 (0)