@ebarooni/capacitor-calendar 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -29
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +12 -11
- package/dist/docs.json +110 -19
- package/dist/esm/definitions.d.ts +60 -11
- package/dist/esm/definitions.js +28 -10
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -2
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +31 -10
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +31 -10
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Calendar.swift +14 -0
- package/ios/Plugin/CapacitorCalendar.swift +162 -138
- package/ios/Plugin/CapacitorCalendarPlugin.m +1 -0
- package/ios/Plugin/CapacitorCalendarPlugin.swift +106 -7
- package/ios/Plugin/CapacitorCalendarPluginError.swift +17 -0
- package/ios/Plugin/PermissionState.swift +16 -0
- package/package.json +2 -2
package/dist/plugin.cjs.js
CHANGED
|
@@ -5,18 +5,36 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var core = require('@capacitor/core');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Enum
|
|
9
|
-
*
|
|
10
|
-
* for when something went wrong.
|
|
11
|
-
*
|
|
8
|
+
* Enum representing the selection style for the calendar chooser.
|
|
9
|
+
* @readonly
|
|
12
10
|
* @enum
|
|
13
11
|
*/
|
|
14
|
-
exports.
|
|
15
|
-
(function (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
exports.CalendarChooserSelectionStyle = void 0;
|
|
13
|
+
(function (CalendarChooserSelectionStyle) {
|
|
14
|
+
/**
|
|
15
|
+
* Allows only a single selection in the calendar chooser.
|
|
16
|
+
*/
|
|
17
|
+
CalendarChooserSelectionStyle[CalendarChooserSelectionStyle["SINGLE"] = 0] = "SINGLE";
|
|
18
|
+
/**
|
|
19
|
+
* Allows multiple selections in the calendar chooser.
|
|
20
|
+
*/
|
|
21
|
+
CalendarChooserSelectionStyle[CalendarChooserSelectionStyle["MULTIPLE"] = 1] = "MULTIPLE";
|
|
22
|
+
})(exports.CalendarChooserSelectionStyle || (exports.CalendarChooserSelectionStyle = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Enum representing the display styles for the calendar chooser.
|
|
25
|
+
* @enum
|
|
26
|
+
*/
|
|
27
|
+
exports.CalendarChooserDisplayStyle = void 0;
|
|
28
|
+
(function (CalendarChooserDisplayStyle) {
|
|
29
|
+
/**
|
|
30
|
+
* Display all calendars available for selection.
|
|
31
|
+
*/
|
|
32
|
+
CalendarChooserDisplayStyle[CalendarChooserDisplayStyle["ALL_CALENDARS"] = 0] = "ALL_CALENDARS";
|
|
33
|
+
/**
|
|
34
|
+
* Display only writable calendars available for selection.
|
|
35
|
+
*/
|
|
36
|
+
CalendarChooserDisplayStyle[CalendarChooserDisplayStyle["WRITABLE_CALENDARS_ONLY"] = 1] = "WRITABLE_CALENDARS_ONLY";
|
|
37
|
+
})(exports.CalendarChooserDisplayStyle || (exports.CalendarChooserDisplayStyle = {}));
|
|
20
38
|
|
|
21
39
|
const CapacitorCalendar = core.registerPlugin('CapacitorCalendar', {
|
|
22
40
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorCalendarWeb()),
|
|
@@ -38,6 +56,9 @@ class CapacitorCalendarWeb extends core.WebPlugin {
|
|
|
38
56
|
createEventWithPrompt() {
|
|
39
57
|
throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);
|
|
40
58
|
}
|
|
59
|
+
selectCalendarsWithPrompt() {
|
|
60
|
+
throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);
|
|
61
|
+
}
|
|
41
62
|
}
|
|
42
63
|
|
|
43
64
|
var web = /*#__PURE__*/Object.freeze({
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * Enum for the
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * Enum representing the selection style for the calendar chooser.\n * @readonly\n * @enum\n */\nexport var CalendarChooserSelectionStyle;\n(function (CalendarChooserSelectionStyle) {\n /**\n * Allows only a single selection in the calendar chooser.\n */\n CalendarChooserSelectionStyle[CalendarChooserSelectionStyle[\"SINGLE\"] = 0] = \"SINGLE\";\n /**\n * Allows multiple selections in the calendar chooser.\n */\n CalendarChooserSelectionStyle[CalendarChooserSelectionStyle[\"MULTIPLE\"] = 1] = \"MULTIPLE\";\n})(CalendarChooserSelectionStyle || (CalendarChooserSelectionStyle = {}));\n/**\n * Enum representing the display styles for the calendar chooser.\n * @enum\n */\nexport var CalendarChooserDisplayStyle;\n(function (CalendarChooserDisplayStyle) {\n /**\n * Display all calendars available for selection.\n */\n CalendarChooserDisplayStyle[CalendarChooserDisplayStyle[\"ALL_CALENDARS\"] = 0] = \"ALL_CALENDARS\";\n /**\n * Display only writable calendars available for selection.\n */\n CalendarChooserDisplayStyle[CalendarChooserDisplayStyle[\"WRITABLE_CALENDARS_ONLY\"] = 1] = \"WRITABLE_CALENDARS_ONLY\";\n})(CalendarChooserDisplayStyle || (CalendarChooserDisplayStyle = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorCalendar = registerPlugin('CapacitorCalendar', {\n web: () => import('./web').then(m => new m.CapacitorCalendarWeb()),\n});\nexport * from './definitions';\nexport { CapacitorCalendar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorCalendarWeb extends WebPlugin {\n checkPermission(_options) {\n throw this.unimplemented(`${this.checkPermission.name} is not implemented on the web`);\n }\n checkAllPermissions() {\n throw this.unimplemented(`${this.checkAllPermissions.name} is not implemented on the web`);\n }\n requestPermission(_options) {\n throw this.unimplemented(`${this.requestPermission.name} is not implemented on the web`);\n }\n requestAllPermissions() {\n throw this.unimplemented(`${this.requestAllPermissions.name} is not implemented on the web`);\n }\n createEventWithPrompt() {\n throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);\n }\n selectCalendarsWithPrompt() {\n throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CalendarChooserSelectionStyle","CalendarChooserDisplayStyle","registerPlugin","WebPlugin"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACWA,+CAA8B;AACzC,CAAC,UAAU,6BAA6B,EAAE;AAC1C;AACA;AACA;AACA,IAAI,6BAA6B,CAAC,6BAA6B,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC1F;AACA;AACA;AACA,IAAI,6BAA6B,CAAC,6BAA6B,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAC9F,CAAC,EAAEA,qCAA6B,KAAKA,qCAA6B,GAAG,EAAE,CAAC,CAAC,CAAC;AAC1E;AACA;AACA;AACA;AACWC,6CAA4B;AACvC,CAAC,UAAU,2BAA2B,EAAE;AACxC;AACA;AACA;AACA,IAAI,2BAA2B,CAAC,2BAA2B,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,eAAe,CAAC;AACpG;AACA;AACA;AACA,IAAI,2BAA2B,CAAC,2BAA2B,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC,GAAG,yBAAyB,CAAC;AACxH,CAAC,EAAEA,mCAA2B,KAAKA,mCAA2B,GAAG,EAAE,CAAC,CAAC;;AC7BhE,MAAC,iBAAiB,GAAGC,mBAAc,CAAC,mBAAmB,EAAE;AAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI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
|
-
* Enum
|
|
6
|
-
*
|
|
7
|
-
* for when something went wrong.
|
|
8
|
-
*
|
|
5
|
+
* Enum representing the selection style for the calendar chooser.
|
|
6
|
+
* @readonly
|
|
9
7
|
* @enum
|
|
10
8
|
*/
|
|
11
|
-
exports.
|
|
12
|
-
(function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
exports.CalendarChooserSelectionStyle = void 0;
|
|
10
|
+
(function (CalendarChooserSelectionStyle) {
|
|
11
|
+
/**
|
|
12
|
+
* Allows only a single selection in the calendar chooser.
|
|
13
|
+
*/
|
|
14
|
+
CalendarChooserSelectionStyle[CalendarChooserSelectionStyle["SINGLE"] = 0] = "SINGLE";
|
|
15
|
+
/**
|
|
16
|
+
* Allows multiple selections in the calendar chooser.
|
|
17
|
+
*/
|
|
18
|
+
CalendarChooserSelectionStyle[CalendarChooserSelectionStyle["MULTIPLE"] = 1] = "MULTIPLE";
|
|
19
|
+
})(exports.CalendarChooserSelectionStyle || (exports.CalendarChooserSelectionStyle = {}));
|
|
20
|
+
/**
|
|
21
|
+
* Enum representing the display styles for the calendar chooser.
|
|
22
|
+
* @enum
|
|
23
|
+
*/
|
|
24
|
+
exports.CalendarChooserDisplayStyle = void 0;
|
|
25
|
+
(function (CalendarChooserDisplayStyle) {
|
|
26
|
+
/**
|
|
27
|
+
* Display all calendars available for selection.
|
|
28
|
+
*/
|
|
29
|
+
CalendarChooserDisplayStyle[CalendarChooserDisplayStyle["ALL_CALENDARS"] = 0] = "ALL_CALENDARS";
|
|
30
|
+
/**
|
|
31
|
+
* Display only writable calendars available for selection.
|
|
32
|
+
*/
|
|
33
|
+
CalendarChooserDisplayStyle[CalendarChooserDisplayStyle["WRITABLE_CALENDARS_ONLY"] = 1] = "WRITABLE_CALENDARS_ONLY";
|
|
34
|
+
})(exports.CalendarChooserDisplayStyle || (exports.CalendarChooserDisplayStyle = {}));
|
|
17
35
|
|
|
18
36
|
const CapacitorCalendar = core.registerPlugin('CapacitorCalendar', {
|
|
19
37
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorCalendarWeb()),
|
|
@@ -35,6 +53,9 @@ var capacitorCapacitorCalendar = (function (exports, core) {
|
|
|
35
53
|
createEventWithPrompt() {
|
|
36
54
|
throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);
|
|
37
55
|
}
|
|
56
|
+
selectCalendarsWithPrompt() {
|
|
57
|
+
throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);
|
|
58
|
+
}
|
|
38
59
|
}
|
|
39
60
|
|
|
40
61
|
var web = /*#__PURE__*/Object.freeze({
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * Enum for the
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * Enum representing the selection style for the calendar chooser.\n * @readonly\n * @enum\n */\nexport var CalendarChooserSelectionStyle;\n(function (CalendarChooserSelectionStyle) {\n /**\n * Allows only a single selection in the calendar chooser.\n */\n CalendarChooserSelectionStyle[CalendarChooserSelectionStyle[\"SINGLE\"] = 0] = \"SINGLE\";\n /**\n * Allows multiple selections in the calendar chooser.\n */\n CalendarChooserSelectionStyle[CalendarChooserSelectionStyle[\"MULTIPLE\"] = 1] = \"MULTIPLE\";\n})(CalendarChooserSelectionStyle || (CalendarChooserSelectionStyle = {}));\n/**\n * Enum representing the display styles for the calendar chooser.\n * @enum\n */\nexport var CalendarChooserDisplayStyle;\n(function (CalendarChooserDisplayStyle) {\n /**\n * Display all calendars available for selection.\n */\n CalendarChooserDisplayStyle[CalendarChooserDisplayStyle[\"ALL_CALENDARS\"] = 0] = \"ALL_CALENDARS\";\n /**\n * Display only writable calendars available for selection.\n */\n CalendarChooserDisplayStyle[CalendarChooserDisplayStyle[\"WRITABLE_CALENDARS_ONLY\"] = 1] = \"WRITABLE_CALENDARS_ONLY\";\n})(CalendarChooserDisplayStyle || (CalendarChooserDisplayStyle = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CapacitorCalendar = registerPlugin('CapacitorCalendar', {\n web: () => import('./web').then(m => new m.CapacitorCalendarWeb()),\n});\nexport * from './definitions';\nexport { CapacitorCalendar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorCalendarWeb extends WebPlugin {\n checkPermission(_options) {\n throw this.unimplemented(`${this.checkPermission.name} is not implemented on the web`);\n }\n checkAllPermissions() {\n throw this.unimplemented(`${this.checkAllPermissions.name} is not implemented on the web`);\n }\n requestPermission(_options) {\n throw this.unimplemented(`${this.requestPermission.name} is not implemented on the web`);\n }\n requestAllPermissions() {\n throw this.unimplemented(`${this.requestAllPermissions.name} is not implemented on the web`);\n }\n createEventWithPrompt() {\n throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);\n }\n selectCalendarsWithPrompt() {\n throw this.unimplemented(`${this.createEventWithPrompt.name} is not implemented on the web`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CalendarChooserSelectionStyle","CalendarChooserDisplayStyle","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;AACWA,mDAA8B;IACzC,CAAC,UAAU,6BAA6B,EAAE;IAC1C;IACA;IACA;IACA,IAAI,6BAA6B,CAAC,6BAA6B,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IAC1F;IACA;IACA;IACA,IAAI,6BAA6B,CAAC,6BAA6B,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;IAC9F,CAAC,EAAEA,qCAA6B,KAAKA,qCAA6B,GAAG,EAAE,CAAC,CAAC,CAAC;IAC1E;IACA;IACA;IACA;AACWC,iDAA4B;IACvC,CAAC,UAAU,2BAA2B,EAA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,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACrG,KAAK;IACL,IAAI,yBAAyB,GAAG;IAChC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACrG,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,156 +3,160 @@ import Capacitor
|
|
|
3
3
|
import EventKitUI
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
public class CapacitorCalendar: NSObject, EKEventEditViewDelegate {
|
|
7
|
-
private enum CalendarEventActionResult: String {
|
|
8
|
-
case saved = "saved"
|
|
9
|
-
case canceled = "canceled"
|
|
10
|
-
case error = "error"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
private enum PermissionState: String {
|
|
14
|
-
case granted = "granted"
|
|
15
|
-
case denied = "denied"
|
|
16
|
-
case prompt = "prompt"
|
|
17
|
-
case promptWithRationale = "prompt-with-rationale"
|
|
18
|
-
}
|
|
19
|
-
|
|
6
|
+
public class CapacitorCalendar: NSObject, EKEventEditViewDelegate, EKCalendarChooserDelegate {
|
|
20
7
|
private let bridge: (any CAPBridgeProtocol)?
|
|
21
|
-
private let
|
|
22
|
-
private var
|
|
8
|
+
private let eventStore: EKEventStore
|
|
9
|
+
private var currentCreateEventContinuation: CheckedContinuation<Bool, any Error>?
|
|
10
|
+
private var currentSelectCalendarsContinuation: CheckedContinuation<[[String : String]], any Error>?
|
|
23
11
|
|
|
24
|
-
init(bridge: (any CAPBridgeProtocol)
|
|
12
|
+
init(bridge: (any CAPBridgeProtocol)?, eventStore: EKEventStore) {
|
|
25
13
|
self.bridge = bridge
|
|
14
|
+
self.eventStore = eventStore
|
|
26
15
|
}
|
|
27
16
|
|
|
28
|
-
public func createEventWithPrompt(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
guard let permissionName = call.getString("alias") else {
|
|
43
|
-
call.reject("[CapacitorCalendar.\(#function)] Permission name is not defined")
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
var permissionState: String
|
|
48
|
-
switch EKEventStore.authorizationStatus(for: .event) {
|
|
49
|
-
case .authorized, .fullAccess:
|
|
50
|
-
permissionState = PermissionState.granted.rawValue
|
|
51
|
-
case .denied, .restricted:
|
|
52
|
-
permissionState = PermissionState.denied.rawValue
|
|
53
|
-
case .notDetermined, .writeOnly:
|
|
54
|
-
permissionState = PermissionState.prompt.rawValue
|
|
55
|
-
@unknown default:
|
|
56
|
-
call.reject("[CapacitorCalendar.\(#function)] Could not determine the status of the requested permission")
|
|
57
|
-
return
|
|
17
|
+
public func createEventWithPrompt() async throws -> Bool {
|
|
18
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
19
|
+
guard let viewController = bridge?.viewController else {
|
|
20
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.viewControllerUnavailable)
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Task { @MainActor in
|
|
25
|
+
let eventEditViewController = EKEventEditViewController()
|
|
26
|
+
eventEditViewController.eventStore = eventStore
|
|
27
|
+
viewController.present(eventEditViewController, animated: true, completion: nil)
|
|
28
|
+
eventEditViewController.editViewDelegate = self
|
|
29
|
+
currentCreateEventContinuation = continuation
|
|
30
|
+
}
|
|
58
31
|
}
|
|
59
|
-
call.resolve(["result": permissionState])
|
|
60
32
|
}
|
|
61
33
|
|
|
62
|
-
public func
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
34
|
+
public func selectCalendarsWithPrompt(selectionStyle: Int, displayStyle: Int) async throws -> [[String: String]] {
|
|
35
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
36
|
+
guard let viewController = bridge?.viewController else {
|
|
37
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.viewControllerUnavailable)
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Task { @MainActor in
|
|
42
|
+
let calendarChooser = EKCalendarChooser(
|
|
43
|
+
selectionStyle: EKCalendarChooserSelectionStyle(rawValue: selectionStyle)!,
|
|
44
|
+
displayStyle: EKCalendarChooserDisplayStyle(rawValue: displayStyle)!,
|
|
45
|
+
eventStore: eventStore
|
|
46
|
+
)
|
|
47
|
+
calendarChooser.showsDoneButton = true
|
|
48
|
+
calendarChooser.showsCancelButton = true
|
|
49
|
+
viewController.present(
|
|
50
|
+
UINavigationController(rootViewController: calendarChooser),
|
|
51
|
+
animated: true,
|
|
52
|
+
completion: nil
|
|
53
|
+
)
|
|
54
|
+
calendarChooser.delegate = self
|
|
55
|
+
currentSelectCalendarsContinuation = continuation
|
|
56
|
+
}
|
|
73
57
|
}
|
|
74
58
|
}
|
|
75
59
|
|
|
76
|
-
public func
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
60
|
+
public func checkAllPermissions() async throws -> [String: String] {
|
|
61
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
62
|
+
var permissionsState: [String: String]
|
|
63
|
+
switch EKEventStore.authorizationStatus(for: .event) {
|
|
64
|
+
case .authorized, .fullAccess:
|
|
65
|
+
permissionsState = [
|
|
66
|
+
"readCalendar": PermissionState.granted.rawValue,
|
|
67
|
+
"writeCalendar": PermissionState.granted.rawValue
|
|
68
|
+
]
|
|
69
|
+
case .denied, .restricted:
|
|
70
|
+
permissionsState = [
|
|
71
|
+
"readCalendar": PermissionState.denied.rawValue,
|
|
72
|
+
"writeCalendar": PermissionState.denied.rawValue
|
|
73
|
+
]
|
|
74
|
+
case .writeOnly:
|
|
75
|
+
permissionsState = [
|
|
76
|
+
"readCalendar": PermissionState.prompt.rawValue,
|
|
77
|
+
"writeCalendar": PermissionState.granted.rawValue
|
|
78
|
+
]
|
|
79
|
+
case .notDetermined:
|
|
80
|
+
permissionsState = [
|
|
81
|
+
"readCalendar": PermissionState.prompt.rawValue,
|
|
82
|
+
"writeCalendar": PermissionState.prompt.rawValue
|
|
83
|
+
]
|
|
84
|
+
@unknown default:
|
|
85
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.unknownPermissionStatus)
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
continuation.resume(returning: permissionsState)
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
public func
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
public func requestWriteAccessToEvents() async throws -> [String: String] {
|
|
93
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
94
|
+
if #available(iOS 17.0, *) {
|
|
95
|
+
eventStore.requestWriteOnlyAccessToEvents { granted, error in
|
|
96
|
+
if let error = error {
|
|
97
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var permissionState: String
|
|
102
|
+
if granted {
|
|
103
|
+
permissionState = PermissionState.granted.rawValue
|
|
104
|
+
} else {
|
|
105
|
+
permissionState = PermissionState.denied.rawValue
|
|
106
|
+
}
|
|
107
|
+
continuation.resume(returning: ["result": permissionState])
|
|
102
108
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var permissionState: String
|
|
118
|
-
if granted {
|
|
119
|
-
permissionState = PermissionState.granted.rawValue
|
|
120
|
-
} else {
|
|
121
|
-
permissionState = PermissionState.denied.rawValue
|
|
109
|
+
} else {
|
|
110
|
+
eventStore.requestAccess(to: .event) { granted, error in
|
|
111
|
+
if let error = error {
|
|
112
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var permissionState: String
|
|
117
|
+
if granted {
|
|
118
|
+
permissionState = PermissionState.granted.rawValue
|
|
119
|
+
} else {
|
|
120
|
+
permissionState = PermissionState.denied.rawValue
|
|
121
|
+
}
|
|
122
|
+
continuation.resume(returning: ["result": permissionState])
|
|
122
123
|
}
|
|
123
|
-
call.resolve(["result": permissionState])
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
permissionState
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
store.requestAccess(to: .event) { granted, error in
|
|
145
|
-
if let error = error {
|
|
146
|
-
call.reject("[CapacitorCalendar.\(#function)] Could not authorize readCalendar and writeCalendar")
|
|
147
|
-
return
|
|
128
|
+
public func requestFullAccessToEvents() async throws -> String {
|
|
129
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
130
|
+
if #available(iOS 17.0, *) {
|
|
131
|
+
eventStore.requestFullAccessToEvents { granted, error in
|
|
132
|
+
if let error = error {
|
|
133
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var permissionState: String
|
|
138
|
+
if granted {
|
|
139
|
+
permissionState = PermissionState.granted.rawValue
|
|
140
|
+
} else {
|
|
141
|
+
permissionState = PermissionState.denied.rawValue
|
|
142
|
+
}
|
|
143
|
+
continuation.resume(returning: permissionState)
|
|
148
144
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
} else {
|
|
146
|
+
eventStore.requestAccess(to: .event) { granted, error in
|
|
147
|
+
if let error = error {
|
|
148
|
+
continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var permissionState: String
|
|
153
|
+
if granted {
|
|
154
|
+
permissionState = PermissionState.granted.rawValue
|
|
155
|
+
} else {
|
|
156
|
+
permissionState = PermissionState.denied.rawValue
|
|
157
|
+
}
|
|
158
|
+
continuation.resume(returning: permissionState)
|
|
154
159
|
}
|
|
155
|
-
call.resolve(["readCalendar": permissionState])
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
}
|
|
@@ -162,20 +166,40 @@ public class CapacitorCalendar: NSObject, EKEventEditViewDelegate {
|
|
|
162
166
|
didCompleteWith action: EKEventEditViewAction
|
|
163
167
|
) {
|
|
164
168
|
controller.dismiss(animated: true) {
|
|
165
|
-
print(action)
|
|
166
169
|
if action == .saved {
|
|
167
|
-
self.
|
|
168
|
-
"result": CalendarEventActionResult.saved.rawValue
|
|
169
|
-
])
|
|
170
|
+
self.currentCreateEventContinuation?.resume(returning: true)
|
|
170
171
|
} else if action == .canceled {
|
|
171
|
-
self.
|
|
172
|
-
"result": CalendarEventActionResult.canceled.rawValue
|
|
173
|
-
])
|
|
172
|
+
self.currentCreateEventContinuation?.resume(returning: false)
|
|
174
173
|
} else {
|
|
175
|
-
self.
|
|
176
|
-
"result": CalendarEventActionResult.error.rawValue
|
|
177
|
-
])
|
|
174
|
+
self.currentCreateEventContinuation?.resume(throwing: CapacitorCalendarPluginError.unknownActionEventCreationPrompt)
|
|
178
175
|
}
|
|
179
176
|
}
|
|
180
177
|
}
|
|
178
|
+
|
|
179
|
+
public func calendarChooserDidFinish(_ calendarChooser: EKCalendarChooser) {
|
|
180
|
+
let selectedCalendars = convertEKCalendarsToDictionaries(calendars: calendarChooser.selectedCalendars)
|
|
181
|
+
bridge?.viewController?.dismiss(animated: true) {
|
|
182
|
+
self.currentSelectCalendarsContinuation?.resume(returning: selectedCalendars)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public func calendarChooserDidCancel(_ calendarChooser: EKCalendarChooser) {
|
|
187
|
+
bridge?.viewController?.dismiss(animated: true) {
|
|
188
|
+
self.currentSelectCalendarsContinuation?.resume(throwing: CapacitorCalendarPluginError.canceledCalendarsSelectionPrompt)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private func convertEKCalendarsToDictionaries(calendars: Set<EKCalendar>) -> [[String: String]] {
|
|
193
|
+
var result: [[String: String]] = []
|
|
194
|
+
|
|
195
|
+
for calendar in calendars {
|
|
196
|
+
let calendarDict: [String: String] = [
|
|
197
|
+
"id": calendar.calendarIdentifier,
|
|
198
|
+
"title": calendar.title
|
|
199
|
+
]
|
|
200
|
+
result.append(calendarDict)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return result
|
|
204
|
+
}
|
|
181
205
|
}
|
|
@@ -9,4 +9,5 @@ CAP_PLUGIN(CapacitorCalendarPlugin, "CapacitorCalendar",
|
|
|
9
9
|
CAP_PLUGIN_METHOD(checkAllPermissions, CAPPluginReturnPromise);
|
|
10
10
|
CAP_PLUGIN_METHOD(requestPermission, CAPPluginReturnPromise);
|
|
11
11
|
CAP_PLUGIN_METHOD(requestAllPermissions, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(selectCalendarsWithPrompt, CAPPluginReturnPromise);
|
|
12
13
|
)
|