所以我通过本教程了解了如何让手机提供触觉反馈。 https://swifttom.com/2020/03/11/haptic-feedback-in-a-swiftui-button/
但是,我想弄清楚的是如何让 iPhone 真正振动,就像在电话静音时接听电话或计时器(来自默认时钟应用程序)关闭时发生的振动一样。我知道这似乎我可以在 Google 上轻松找到答案,但老实说我找不到解决方案。如果有人可以提供帮助,将不胜感激。
import SwiftUI
struct ContentView: View {
let generator = UINotificationFeedbackGenerator()
var body: some View {
VStack{
Button("Press") {
generator.notificationOccurred(.error) //I want vibration, not haptic feedback
}
}
}
}