Skip to content

Commit 886a6a3

Browse files
authored
Fix permissions on macOS Sonoma (#70)
The old API now fails 100% of the time and you have to use the new API. This also starts printing the returned error in this case for the future.
1 parent a7a062f commit 886a6a3

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

.github/workflows/swift.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ name: Swift
88

99
jobs:
1010
build:
11-
runs-on: macos-latest
11+
runs-on: macos-13
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
14+
- name: xcode-select
15+
run: sudo xcode-select -s /Applications/Xcode_15.0.app
1416
- name: Build
1517
run: swift build -Xswiftc -warnings-as-errors
1618
- name: Test

Sources/RemindersLibrary/Reminders.swift

+15-5
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,26 @@ public enum Priority: String, ExpressibleByArgument {
6363
}
6464

6565
public final class Reminders {
66-
public static func requestAccess() -> Bool {
66+
public static func requestAccess() -> (Bool, Error?) {
6767
let semaphore = DispatchSemaphore(value: 0)
6868
var grantedAccess = false
69-
Store.requestAccess(to: .reminder) { granted, _ in
70-
grantedAccess = granted
71-
semaphore.signal()
69+
var returnError: Error? = nil
70+
if #available(macOS 14.0, *) {
71+
Store.requestFullAccessToReminders { granted, error in
72+
grantedAccess = granted
73+
returnError = error
74+
semaphore.signal()
75+
}
76+
} else {
77+
Store.requestAccess(to: .reminder) { granted, error in
78+
grantedAccess = granted
79+
returnError = error
80+
semaphore.signal()
81+
}
7282
}
7383

7484
semaphore.wait()
75-
return grantedAccess
85+
return (grantedAccess, returnError)
7686
}
7787

7888
func getListNames() -> [String] {

Sources/reminders/main.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Darwin
22
import RemindersLibrary
33

4-
if Reminders.requestAccess() {
4+
switch Reminders.requestAccess() {
5+
case (true, _):
56
CLI.main()
6-
} else {
7-
print("You need to grant reminders access")
7+
case (false, let error):
8+
print("error: you need to grant reminders access")
9+
if let error {
10+
print("error: \(error.localizedDescription)")
11+
}
812
exit(1)
913
}

0 commit comments

Comments
 (0)