From c0dfb5d2b4860a4452cfaa5558719e15d56e70ce Mon Sep 17 00:00:00 2001 From: Fin Date: Thu, 23 Jan 2025 09:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=93=83=E5=A3=B0=E6=97=B6=EF=BC=8C=E4=B8=80=E8=B5=B7=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20call=20=E7=94=9F=E6=88=90=E7=9A=84=E9=95=BF?= =?UTF-8?q?=E9=93=83=E5=A3=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/SoundsViewModel.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Controller/SoundsViewModel.swift b/Controller/SoundsViewModel.swift index 288ba6ef..7d4d0ba9 100644 --- a/Controller/SoundsViewModel.swift +++ b/Controller/SoundsViewModel.swift @@ -91,7 +91,7 @@ class SoundsViewModel: ViewModel, ViewModelType { guard case SoundItem.sound(let model) = item else { return } - self.dependencies.soundFileStorage.deleteSound(url: model.model.url) + self.dependencies.soundFileStorage.deleteSound(name: model.model.url.lastPathComponent) }).disposed(by: rx.disposeBag) // 铃声列表有更新 @@ -169,7 +169,7 @@ class SoundsViewModel: ViewModel, ViewModelType { /// 保存铃声文件协议 protocol SoundFileStorageProtocol { func saveSound(url: URL) - func deleteSound(url: URL) + func deleteSound(name: String) } /// 用于将铃声文件保存在 /Library/Sounds 文件夹中 @@ -189,9 +189,16 @@ class SoundFileStorage: SoundFileStorageProtocol { try? fileManager.copyItem(at: url, to: soundUrl) } - func deleteSound(url: URL) { - // 删除sounds目录铃声文件 - try? fileManager.removeItem(at: url) + func deleteSound(name: String) { + guard let soundsDirectoryUrl = getSoundsDirectory() else { + return + } + let soundUrl = soundsDirectoryUrl.appendingPathComponent(name) + let callSoundUrl = soundsDirectoryUrl.appendingPathComponent("\(kBarkSoundPrefix).\(name)") + // 删除 sounds 目录铃声文件 + try? fileManager.removeItem(at: soundUrl) + // 删除 call=1 生成的铃声文件 + try? fileManager.removeItem(at: callSoundUrl) } /// 获取 Library 目录下的 Sounds 文件夹