SwiftUI 在按下按钮时添加声音效果

Tho*_*son 1 swiftui

我想在我的 SwiftUI 应用程序中按下按钮时添加声音效果。该按钮还有一个功能,但我只想添加一个声音效果。我已经使用 UIkit 找到了先前版本的 Xcode 的信息,但我不明白如何在 SwiftUI 中执行此操作。

编辑:如果这解释了我缺乏知识,我对编程很陌生。

wor*_*dog 5

from answer: Play reminder sound SwiftUI

you can use this simple method:

import AVFoundation

AudioServicesPlaySystemSound(1026)
Run Code Online (Sandbox Code Playgroud)

where the number 1026 is the SystemSound id.