forked from DroidKaigi/conference-app-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
158 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import EventKit | ||
import UIKit | ||
|
||
public protocol EventKitClientProtocol { | ||
func requestAccessIfNeeded() async throws -> Bool | ||
func addEvent( | ||
title: String, | ||
startDate: Date, | ||
endDate: Date | ||
) throws | ||
} | ||
|
||
public struct EventKitClient: EventKitClientProtocol { | ||
private let eventStore = EKEventStore() | ||
|
||
public init() {} | ||
|
||
public func requestAccessIfNeeded() async throws -> Bool { | ||
switch EKEventStore.authorizationStatus(for: .event) { | ||
case .denied, .restricted: | ||
let _ = await UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) | ||
case .authorized: | ||
return true | ||
case .notDetermined: | ||
break | ||
@unknown default: | ||
break | ||
} | ||
return try await eventStore.requestAccess(to: .event) | ||
} | ||
|
||
public func addEvent( | ||
title: String, | ||
startDate: Date, | ||
endDate: Date | ||
) throws { | ||
guard let defaultCalendar = eventStore.defaultCalendarForNewEvents else { | ||
return | ||
} | ||
let event = EKEvent(eventStore: eventStore) | ||
event.title = title | ||
event.startDate = startDate | ||
event.endDate = endDate | ||
event.calendar = defaultCalendar | ||
|
||
try eventStore.save(event, span: .thisEvent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
public struct EventKitClientMock: EventKitClientProtocol { | ||
public init() {} | ||
|
||
public func requestAccessIfNeeded() async throws -> Bool { | ||
return true | ||
} | ||
|
||
public func addEvent(title: String, startDate: Date, endDate: Date) throws {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters