From b709b6da2436b501579d0de4a13985cf06f228aa Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Apr 2023 14:59:03 +0200 Subject: [PATCH] Added logs and activate audio session each time the app enters the foreground --- LeCountdown.xcodeproj/project.pbxproj | 6 ++++++ .../xcshareddata/xcschemes/LeCountdown.xcscheme | 7 ------- LeCountdown/AppDelegate.swift | 8 +++++++- LeCountdown/Conductor.swift | 16 +++++++++------- LeCountdown/Model/Model+SharedExtensions.swift | 1 + LeCountdown/Model/Persistence.swift | 3 +++ LeCountdown/Sound/DelaySoundPlayer.swift | 9 ++++----- LeCountdown/Utils/TextToSpeechRecorder.swift | 1 + 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index f56161f..46b93df 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -114,6 +114,9 @@ C4742B59298411E800D5D950 /* CountdownFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B58298411E800D5D950 /* CountdownFormView.swift */; }; C4742B5B298414B000D5D950 /* ImageSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B5A298414B000D5D950 /* ImageSelectionView.swift */; }; C4742B5F2984205000D5D950 /* ViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B5E2984205000D5D950 /* ViewModifiers.swift */; }; + C47C933529F01B5E00C780E2 /* FileLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4556F6A29E40B7800DEB40B /* FileLogger.swift */; }; + C47C933629F01B6600C780E2 /* FileUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4556F6E29E40BED00DEB40B /* FileUtils.swift */; }; + C47C933729F01B7A00C780E2 /* Codable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4556F7029E40DCF00DEB40B /* Codable+Extensions.swift */; }; C48ECC0829DAC45900DE5A66 /* AppGuard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B56299FFA4F00CB4FBA /* AppGuard.swift */; }; C48ECC0929DAC47200DE5A66 /* AppGuard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B56299FFA4F00CB4FBA /* AppGuard.swift */; }; C498E59F298D4DEA00E90DE0 /* LiveTimerListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C498E59E298D4DEA00E90DE0 /* LiveTimerListView.swift */; }; @@ -1349,6 +1352,7 @@ C498E5A6299152C600E90DE0 /* GreenCheckmarkView.swift in Sources */, C4BA2B3B299F838000CB4FBA /* Model+SharedExtensions.swift in Sources */, C438C7EB2981266F00BF3EF9 /* SingleTimerView.swift in Sources */, + C47C933729F01B7A00C780E2 /* Codable+Extensions.swift in Sources */, C438C7D62981216200BF3EF9 /* LaunchWidgetBundle.swift in Sources */, C4BA2B16299BE6A000CB4FBA /* IntervalGroup+CoreDataClass.swift in Sources */, C4F8B18B298AC288005C86A5 /* Record+CoreDataClass.swift in Sources */, @@ -1358,6 +1362,7 @@ C4BA2AF72996A4EF00CB4FBA /* CustomSound+CoreDataClass.swift in Sources */, C4F8B1AD298AC451005C86A5 /* AbstractSoundTimer+CoreDataClass.swift in Sources */, C445FA87298448730054D761 /* CoolPic.swift in Sources */, + C47C933529F01B5E00C780E2 /* FileLogger.swift in Sources */, C438C8162982BE1E00BF3EF9 /* LeCountdown.xcdatamodeld in Sources */, C4BA2B4A299FCE0C00CB4FBA /* IntervalGroup+CoreDataProperties.swift in Sources */, C4BA2B4D299FCE0C00CB4FBA /* Stopwatch+CoreDataProperties.swift in Sources */, @@ -1376,6 +1381,7 @@ C438C7DA2981216200BF3EF9 /* LaunchWidget.swift in Sources */, C4BA2AF62996A4EF00CB4FBA /* CustomSound+CoreDataProperties.swift in Sources */, C4F8B192298AC288005C86A5 /* Activity+CoreDataProperties.swift in Sources */, + C47C933629F01B6600C780E2 /* FileUtils.swift in Sources */, C4BA2B18299BE6A000CB4FBA /* Interval+CoreDataClass.swift in Sources */, C4F8B18E298AC288005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */, C4A16DC829D311C800143D5E /* Extensions.swift in Sources */, diff --git a/LeCountdown.xcodeproj/xcshareddata/xcschemes/LeCountdown.xcscheme b/LeCountdown.xcodeproj/xcshareddata/xcschemes/LeCountdown.xcscheme index 7113a0f..22e466d 100644 --- a/LeCountdown.xcodeproj/xcshareddata/xcschemes/LeCountdown.xcscheme +++ b/LeCountdown.xcodeproj/xcshareddata/xcschemes/LeCountdown.xcscheme @@ -64,13 +64,6 @@ isEnabled = "YES"> - - - - String { + return IntentDataProvider.main.timer(id: id)?.name ?? id + } + } diff --git a/LeCountdown/Model/Model+SharedExtensions.swift b/LeCountdown/Model/Model+SharedExtensions.swift index 6fcc332..dfbf649 100644 --- a/LeCountdown/Model/Model+SharedExtensions.swift +++ b/LeCountdown/Model/Model+SharedExtensions.swift @@ -27,6 +27,7 @@ extension AbstractTimer { if let url = URL(string: self.stringId) { return url } else { +// FileLogger.log("app terminated by ourselves") fatalError("Can't produce url with \(self.stringId)") } } diff --git a/LeCountdown/Model/Persistence.swift b/LeCountdown/Model/Persistence.swift index 7756d3f..fa6c830 100644 --- a/LeCountdown/Model/Persistence.swift +++ b/LeCountdown/Model/Persistence.swift @@ -53,6 +53,7 @@ struct PersistenceController { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. let nsError = error as NSError + FileLogger.log("app terminated by ourselves") fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } return result @@ -101,6 +102,7 @@ struct PersistenceController { * The store could not be migrated to the current model version. Check the error message to determine what the actual problem was. */ + FileLogger.log("app terminated by ourselves") fatalError("Unresolved error \(error), \(error.userInfo)") } }) @@ -114,6 +116,7 @@ fileprivate extension URL { /// Returns a URL for the given app group and database pointing to the sqlite database. static func storeURL(for appGroup: String, databaseName: String) -> URL { guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else { + FileLogger.log("app terminated by ourselves") fatalError("Shared file container could not be created.") } diff --git a/LeCountdown/Sound/DelaySoundPlayer.swift b/LeCountdown/Sound/DelaySoundPlayer.swift index 2bd013d..15dd023 100644 --- a/LeCountdown/Sound/DelaySoundPlayer.swift +++ b/LeCountdown/Sound/DelaySoundPlayer.swift @@ -46,8 +46,8 @@ import AVFoundation Logger.log("self._player.deviceCurrentTime = \(self._player.deviceCurrentTime)") let time: TimeInterval = self._player.deviceCurrentTime + duration - self._player.play(atTime: time) - FileLogger.log("self._player.play(atTime: \(time)") + let result = self._player.play(atTime: time) + FileLogger.log("play \(String(describing: self._player.url)) >atTime: \(time), result = \(result), isMainThread = \(Thread.isMainThread)") } func stop() { @@ -58,10 +58,9 @@ import AVFoundation // MARK: - Delegate func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { - FileLogger.log("audioPlayerDidFinishPlaying: successfully = \(flag)") - + FileLogger.log("audioPlayerDidFinishPlaying: successfully = \(flag), player volume = \(player.volume)") + Logger.log("audioPlayerDidFinishPlaying: successfully = \(flag)") -// Conductor.maestro.cancelSoundPlayer(id: self._timerID) Conductor.maestro.cleanupLiveActivities() self.stop() diff --git a/LeCountdown/Utils/TextToSpeechRecorder.swift b/LeCountdown/Utils/TextToSpeechRecorder.swift index e9a0d23..6862c01 100644 --- a/LeCountdown/Utils/TextToSpeechRecorder.swift +++ b/LeCountdown/Utils/TextToSpeechRecorder.swift @@ -27,6 +27,7 @@ class TextToSpeechRecorder { synthesizer.write(utterance) { buffer in guard let pcmBuffer = buffer as? AVAudioPCMBuffer else { + FileLogger.log("app terminated by ourselves") fatalError("unknown buffer type: \(buffer)") } let fileName = "\(UUID().uuidString).caf"