Skip to content

Commit

Permalink
Re-instate support for asking for calendar access on iOS 17 (#317)
Browse files Browse the repository at this point in the history
The old `requestAccess(to: .event)` immediately errors.
  • Loading branch information
nighthawk authored Nov 24, 2023
1 parent 529ed21 commit 5434956
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs-dryrun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
build_docs:
name: Build docs
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout main
uses: actions/checkout@v2
uses: actions/checkout@v4
- uses: actions/setup-python@v2
with:
python-version: 3.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
build_docs:
name: Build and deploy docs
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout main
uses: actions/checkout@v2
uses: actions/checkout@v4
- uses: actions/setup-python@v2
with:
python-version: 3.x
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ on:

jobs:
build_spm:
runs-on: macos-12
runs-on: macos-13

steps:
- uses: actions/checkout@v3
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v4
- name: Build
run: swift build --target TripKit

build_xcode:
runs-on: macos-12
runs-on: macos-13

steps:
- uses: maxim-lobanov/setup-xcode@v1
Expand All @@ -31,13 +34,13 @@ jobs:
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKitInterApp-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'

test_xcode:
runs-on: macos-12
runs-on: macos-13

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run tests
env:
TRIPGO_API_KEY: ${{ secrets.TRIPGO_API_KEY }}
Expand All @@ -55,13 +58,13 @@ jobs:
# even if the test fails in the previous step.

examples:
runs-on: macos-12
runs-on: macos-13

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build TripKitUIExample
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme TripKitUIExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'
- name: Build MiniMap
Expand Down
2 changes: 1 addition & 1 deletion Examples/MiniMap/MiniMap/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 SkedGo Pty Ltd. All rights reserved.
//

import Cocoa
import AppKit

import TripKit

Expand Down
2 changes: 1 addition & 1 deletion Examples/MiniMap/MiniMap/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 SkedGo Pty Ltd. All rights reserved.
//

import Cocoa
import AppKit
import MapKit

import TripKit
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let package = Package(
"TGCardViewController",
"GeoMonitor",
],
exclude: ["Supporting Files/Info.plist"]
exclude: ["Supporting Files/Info.plist", "vendor/RxCombine/LICENSE"]
),
.testTarget(
name: "TripKitTests",
Expand Down
2 changes: 1 addition & 1 deletion Sources/TripKit/core/TKCrossPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation
public typealias TKImage = UIImage
public typealias TKFont = UIFont
#elseif os(OSX)
import Cocoa
import AppKit
public typealias TKColor = NSColor
public typealias TKImage = NSImage
public typealias TKFont = NSFont
Expand Down
21 changes: 15 additions & 6 deletions Sources/TripKit/managers/TKCalendarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ extension TKCalendarManager: TKPermissionManager {
return .notDetermined
case .restricted:
return .restricted
case .denied:
case .denied, .writeOnly:
return .denied
case .authorized:
case .authorized, .fullAccess:
return .authorized
@unknown default:
return .notDetermined
Expand All @@ -87,10 +87,19 @@ extension TKCalendarManager: TKPermissionManager {

public func askForPermission(_ completion: @escaping (Bool) -> Void) {
let oldStore = self.eventStore
oldStore.requestAccess(to: .event) { granted, _ in
self.eventStore = .init()
DispatchQueue.main.async {
completion(granted)
if #available(iOS 17.0, macOS 14.0, *) {
oldStore.requestFullAccessToEvents { granted, _ in
self.eventStore = .init()
DispatchQueue.main.async {
completion(granted)
}
}
} else {
oldStore.requestAccess(to: .event) { granted, _ in
self.eventStore = .init()
DispatchQueue.main.async {
completion(granted)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/TripKit/vendor/ASPolygonKit/QuickLookable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
#if os(iOS) || os(tvOS)
import UIKit
#elseif os(OSX)
import Cocoa
import AppKit
#endif

extension Polygon {
Expand Down
6 changes: 3 additions & 3 deletions Sources/TripKitUI/views/trip overview/TKUIPathChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import class TripKit.Shape

@available(iOS 16.0, *)
struct TKUIPathChartView<V>: View where V: TKUIPathChartable & Hashable {
init?(values: [TKUIPathChartView.ChartValue<V>], totalDistance: CLLocationDistance? = nil) {
init?(values: [TKUIPathChartView.ChartValue], totalDistance: CLLocationDistance? = nil) {
let longEnough = values.filter { $0.distance > 25 }
guard !longEnough.isEmpty else { return nil }

Expand All @@ -37,12 +37,12 @@ struct TKUIPathChartView<V>: View where V: TKUIPathChartable & Hashable {
}
}

struct ChartValue<V>: Hashable where V: TKUIPathChartable & Hashable {
struct ChartValue: Hashable {
var value: V
var distance: CLLocationDistance
}

let values: [ChartValue<V>]
let values: [ChartValue]
let totalDistance: CLLocationDistance

var body: some View {
Expand Down

0 comments on commit 5434956

Please sign in to comment.