forked from mirrors/linphone-iphone
Add NSCalendarsUsageDescription and NSCalendarsWriteOnlyAccessUsageDescriptions to info.plist
This commit is contained in:
parent
96d8a879b8
commit
8059dd4470
5 changed files with 104 additions and 24 deletions
|
|
@ -37,6 +37,7 @@
|
|||
66FBFC492B83BD2400BC6AB1 /* ConfigExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491F82B24D25A00CEA16D /* ConfigExtension.swift */; };
|
||||
66FBFC4A2B83BD3300BC6AB1 /* FileUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FE2B24D4AC00CEA16D /* FileUtils.swift */; };
|
||||
66FBFC4B2B83BD7B00BC6AB1 /* CoreExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FA2B24D32600CEA16D /* CoreExtension.swift */; };
|
||||
66FDB7812C7C689A00561566 /* EventEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FDB7802C7C689A00561566 /* EventEditViewController.swift */; };
|
||||
C60E8F192C0F649200A06DB8 /* UIApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C60E8F182C0F649200A06DB8 /* UIApplicationExtension.swift */; };
|
||||
C62817282C1B389700DBA646 /* SideMenuAccountRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C62817272C1B389700DBA646 /* SideMenuAccountRow.swift */; };
|
||||
C628172E2C1C3A3600DBA646 /* AccountExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C628172D2C1C3A3600DBA646 /* AccountExtension.swift */; };
|
||||
|
|
@ -218,6 +219,7 @@
|
|||
66E56BCD2BA9A1F8006CE56F /* MeetingModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingModel.swift; sourceTree = "<group>"; };
|
||||
66F08C882C2AFEF700D9AE2F /* MeetingsListBottomSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingsListBottomSheet.swift; sourceTree = "<group>"; };
|
||||
66F626B12BCEBB86003E2DEC /* AddParticipantsFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddParticipantsFragment.swift; sourceTree = "<group>"; };
|
||||
66FDB7802C7C689A00561566 /* EventEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventEditViewController.swift; sourceTree = "<group>"; };
|
||||
C60E8F182C0F649200A06DB8 /* UIApplicationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplicationExtension.swift; sourceTree = "<group>"; };
|
||||
C62817272C1B389700DBA646 /* SideMenuAccountRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuAccountRow.swift; sourceTree = "<group>"; };
|
||||
C628172D2C1C3A3600DBA646 /* AccountExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountExtension.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -439,6 +441,7 @@
|
|||
children = (
|
||||
66E56BC82BA4A6D7006CE56F /* MeetingsListViewModel.swift */,
|
||||
6613A0B32BAEBE3F008923A4 /* MeetingViewModel.swift */,
|
||||
66FDB7802C7C689A00561566 /* EventEditViewController.swift */,
|
||||
);
|
||||
path = ViewModel;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -1082,6 +1085,7 @@
|
|||
D7B5678E2B28888F00DE63EB /* CallView.swift in Sources */,
|
||||
D71A0E192B485ADF0002C6CD /* ViewExtension.swift in Sources */,
|
||||
D759CB642C3FBD4200AC35E8 /* StartConversationFragment.swift in Sources */,
|
||||
66FDB7812C7C689A00561566 /* EventEditViewController.swift in Sources */,
|
||||
D750D3392AD3E6EE00EC99C5 /* PopupLoadingView.swift in Sources */,
|
||||
D7E6D0492AE933AD00A57AAF /* FavoriteContactsListFragment.swift in Sources */,
|
||||
662B69DB2B25DE25007118BF /* ProviderDelegate.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -198,6 +198,9 @@
|
|||
},
|
||||
"Add the contact" : {
|
||||
|
||||
},
|
||||
"Add to calendar" : {
|
||||
|
||||
},
|
||||
"Add to contacts" : {
|
||||
|
||||
|
|
@ -1483,6 +1486,9 @@
|
|||
},
|
||||
"Marquer comme non lu" : {
|
||||
|
||||
},
|
||||
"Meeting added to iPhone calendar" : {
|
||||
|
||||
},
|
||||
"Meetings" : {
|
||||
|
||||
|
|
@ -1906,7 +1912,7 @@
|
|||
"This contact will be deleted definitively." : {
|
||||
|
||||
},
|
||||
"Time Zone:" : {
|
||||
"Time Zone: %@" : {
|
||||
|
||||
},
|
||||
"Title" : {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ struct MeetingFragment: View {
|
|||
|
||||
@State private var showDatePicker = false
|
||||
@State private var showTimePicker = false
|
||||
@State private var showEventEditView = false
|
||||
|
||||
@State var selectedDate = Date.now
|
||||
@State var setFromDate: Bool = true
|
||||
|
|
@ -107,6 +108,25 @@ struct MeetingFragment: View {
|
|||
}
|
||||
|
||||
Menu {
|
||||
Button {
|
||||
if #available(iOS 17.0, *) {
|
||||
withAnimation {
|
||||
showEventEditView.toggle()
|
||||
}
|
||||
} else {
|
||||
meetingViewModel.addMeetingToCalendar()
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Image("calendar")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.frame(width: 25, height: 25, alignment: .leading)
|
||||
Text("Add to calendar")
|
||||
.default_text_style(styleSize: 16)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
Button(role: .destructive) {
|
||||
withAnimation {
|
||||
meetingsListViewModel.selectedMeetingToDelete = meetingViewModel.displayedMeeting
|
||||
|
|
@ -292,7 +312,9 @@ struct MeetingFragment: View {
|
|||
.padding(.leading, 15)
|
||||
.padding(.trailing, 15)
|
||||
})
|
||||
}
|
||||
}.sheet(isPresented: $showEventEditView, content: { // $showEventEditView only edited on iOS17+
|
||||
EventEditViewController(meetingViewModel: self.meetingViewModel)
|
||||
})
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2024 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-iphone
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import EventKitUI
|
||||
import SwiftUI
|
||||
|
||||
struct EventEditViewController: UIViewControllerRepresentable {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
let meetingViewModel: MeetingViewModel
|
||||
|
||||
class Coordinator: NSObject, EKEventEditViewDelegate {
|
||||
var parent: EventEditViewController
|
||||
|
||||
init(_ controller: EventEditViewController) {
|
||||
self.parent = controller
|
||||
}
|
||||
|
||||
func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
|
||||
parent.presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
return Coordinator(self)
|
||||
}
|
||||
|
||||
typealias UIViewControllerType = EKEventEditViewController
|
||||
func makeUIViewController(context: Context) -> EKEventEditViewController {
|
||||
let eventEditViewController = EKEventEditViewController()
|
||||
eventEditViewController.event = meetingViewModel.createMeetingEKEvent()
|
||||
eventEditViewController.eventStore = meetingViewModel.eventStore
|
||||
eventEditViewController.editViewDelegate = context.coordinator
|
||||
return eventEditViewController
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: EKEventEditViewController, context: Context) {}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ import EventKit
|
|||
// swiftlint:disable line_length
|
||||
class MeetingViewModel: ObservableObject {
|
||||
static let TAG = "[MeetingViewModel]"
|
||||
let eventStore : EKEventStore = EKEventStore()
|
||||
let eventStore: EKEventStore = EKEventStore()
|
||||
|
||||
@Published var isBroadcastSelected: Bool = false
|
||||
@Published var showBroadcastHelp: Bool = false
|
||||
|
|
@ -325,25 +325,26 @@ class MeetingViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
func createMeetingEKEvent() -> EKEvent {
|
||||
let event: EKEvent = EKEvent(eventStore: eventStore)
|
||||
event.title = subject
|
||||
event.startDate = fromDate
|
||||
event.endDate = toDate
|
||||
event.notes = description
|
||||
event.calendar = eventStore.defaultCalendarForNewEvents
|
||||
event.location = "Linphone video meeting"
|
||||
return event
|
||||
}
|
||||
// For iOS 16 and below
|
||||
func addMeetingToCalendar() {
|
||||
|
||||
let addToCalendar = { (granted: Bool, error: (any Error)?) in
|
||||
guard let meeting = self.displayedMeeting else {
|
||||
Log.error("\(MeetingViewModel.TAG) Failed to add meeting to calendar: no meeting selected")
|
||||
return
|
||||
}
|
||||
eventStore.requestAccess(to: .event, completion: { (granted: Bool, error: (any Error)?) in
|
||||
if !granted {
|
||||
Log.error("\(MeetingViewModel.TAG) Failed to add meeting to calendar: access not granted")
|
||||
} else if error == nil {
|
||||
let event: EKEvent = EKEvent(eventStore: self.eventStore)
|
||||
event.title = self.subject
|
||||
event.startDate = self.fromDate
|
||||
event.endDate = self.toDate
|
||||
event.notes = self.description
|
||||
event.calendar = self.eventStore.defaultCalendarForNewEvents
|
||||
let event = self.createMeetingEKEvent()
|
||||
do {
|
||||
try self.eventStore.save(event, span: .thisEvent)
|
||||
Log.info("\(MeetingViewModel.TAG) Meeting '\(meeting.subject)' added to calendar")
|
||||
Log.info("\(MeetingViewModel.TAG) Meeting '\(self.subject)' added to calendar")
|
||||
ToastViewModel.shared.toastMessage = "Meeting_added_to_calendar"
|
||||
ToastViewModel.shared.displayToast = true
|
||||
} catch let error as NSError {
|
||||
|
|
@ -354,15 +355,8 @@ class MeetingViewModel: ObservableObject {
|
|||
} else {
|
||||
Log.error("\(MeetingViewModel.TAG) Failed to add meeting to calendar: \(error?.localizedDescription ?? "")")
|
||||
}
|
||||
}
|
||||
|
||||
if #available(iOS 17.0, *) {
|
||||
eventStore.requestWriteOnlyAccessToEvents(completion: addToCalendar)
|
||||
} else {
|
||||
eventStore.requestAccess(to: .event, completion: addToCalendar)
|
||||
}
|
||||
})
|
||||
}
|
||||
// eventStore.requestAccess(to: EKEntityType.event) { granted, error in
|
||||
}
|
||||
|
||||
// swiftlint:enable line_length
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue