-
Notifications
You must be signed in to change notification settings - Fork 8
Ximluo/gsr sharing merge #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // | ||
| // CalendarHelper.swift | ||
| // PennMobile | ||
| // | ||
| // Created by Ximing Luo on 3/14/25. | ||
| // Copyright © 2025 PennLabs. All rights reserved. | ||
| // | ||
|
|
||
| import EventKit | ||
| import SwiftUI | ||
|
|
||
| struct CalendarHelper { | ||
| static func addToCalendar( | ||
| title: String, | ||
| location: String, | ||
| start: Date, | ||
| end: Date, | ||
| completion: @escaping (Bool) -> Void | ||
| ) { | ||
| let eventStore = EKEventStore() | ||
| eventStore.requestAccess(to: .event) { granted, error in | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use something like requestWriteOnlyAccessToEvents() instead? Alternatively, there's a way to present an |
||
| if granted, error == nil { | ||
| let event = EKEvent(eventStore: eventStore) | ||
| event.title = title | ||
| event.location = location | ||
| event.startDate = start | ||
| event.endDate = end | ||
| event.notes = "Created by PennMobile" | ||
anli5005 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| event.calendar = eventStore.defaultCalendarForNewEvents | ||
|
|
||
| do { | ||
| try eventStore.save(event, span: .thisEvent) | ||
| print("Event added to calendar") | ||
| completion(true) | ||
| } catch { | ||
| print("Failed to save event: \(error)") | ||
| completion(false) | ||
| } | ||
| } else { | ||
| print("Calendar access not granted or error: \(String(describing: error))") | ||
| completion(false) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // | ||
| // GoogleCalendarLink.swift | ||
| // PennMobile | ||
| // | ||
| // Created by Ximing Luo on 3/14/25. | ||
| // Copyright © 2025 PennLabs. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct GoogleCalendarLink { | ||
anli5005 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static func makeURL(title: String, location: String, start: Date, end: Date) -> URL? { | ||
| let dateFormatter = DateFormatter() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can we use ISO8601DateFormatter (or the equivalent listed under the tip) instead? |
||
| dateFormatter.dateFormat = "yyyyMMdd'T'HHmmss'Z'" | ||
| dateFormatter.timeZone = TimeZone(abbreviation: "UTC") | ||
|
|
||
| let startStr = dateFormatter.string(from: start) | ||
| let endStr = dateFormatter.string(from: end) | ||
|
|
||
| let escapedTitle = title.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "Event" | ||
| let escapedLocation = location.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" | ||
|
|
||
| let urlString = "https://calendar.google.com/calendar/render?action=TEMPLATE&text=\(escapedTitle)&location=\(escapedLocation)&dates=\(startStr)/\(endStr)" | ||
|
|
||
| return URL(string: urlString) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Would prefer we made this
async