enum Vibration {
case error
case success
case warning
case light
case medium
case heavy
@available(iOS 13.0, *)
case soft
@available(iOS 13.0, *)
case rigid
case selection
case oldSchool
public func vibrate() {
switch self {
case .error:
UINotificationFeedbackGenerator().notificationOccurred(.error)
case .success:
UINotificationFeedbackGenerator().notificationOccurred(.success)
case .warning:
UINotificationFeedbackGenerator().notificationOccurred(.warning)
case .light:
UIImpactFeedbackGenerator(style: .light).impactOccurred()
case .medium:
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
case .heavy:
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
case .soft:
if #available(iOS 13.0, *) {
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
}
case .rigid:
if #available(iOS 13.0, *) {
UIImpactFeedbackGenerator(style: .rigid).impactOccurred()
}
case .selection:
UISelectionFeedbackGenerator().selectionChanged()
case .oldSchool:
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
}
}
}
stackoverflow.com/questions/26455880/how-to-make-iphone-vibrate-using-swift/57162220
반응형
'iOS > swift' 카테고리의 다른 글
Frameworks/SnapKit.framework/Info.plist: No such file or directory (0) | 2021.03.12 |
---|---|
keyboard extension app, open setting (0) | 2021.03.10 |
pasteboard에 이미지 데이터 넣기 (0) | 2021.02.22 |
한글 자모의 유니코드에 대한 글 (0) | 2021.02.03 |
class JSONNull (0) | 2021.01.19 |