Building Spotify App in Swift 5 & UIKit - Part 26 - Haptics (Xcode 12, 2021, Swift 5) - Build App
import Foundation
import UIKit
final class HapticManager {
static let shared = HapticManager()
private init() {}
public func vibrateForSelection() {
DispatchQueue.main.async {
let generator = UISelectionFeedbackGenerator()
generator.prepare()
generator.selectionChanged()
print("vibrate for selection")
}
}
public func vibrate(for type: UINotificationFeedbackGenerator.FeedbackType) {
DispatchQueue.main.async {
let generator = UINotificationFeedbackGenerator()
generator.prepare()
generator.notificationOccurred(type)
print("vibrate")
}
}
}
vibrateForSelection
함수vibrate
. 타입 파라미터를 통해 사용 가능 @objc private func didTapActions() {
...
// Save album
APICaller.shared.saveAlbum(album: self.album) { success in
if success {
HapticManager.shared.vibrate(for: .success)
NotificationCenter.default.post(name: .albumSavedNotification, object: nil)
print("Saved: \(success)")
} else {
HapticManager.shared.vibrate(for: .error)
}
}
}))
...
}