Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import AVFoundation
import AudioToolbox
struct DeviceFeedback {
enum Haptic: UInt32 {
case impact = 1520
case notification = 1521
case selection = 1519
}
enum Alert: UInt32 {
case smsSent = 1004
case smsReceived = 1003
case contactAdded = 1117
}
// MARK: Lifecycle
private init() {}
// MARK: Static
static func sound(_ alert: Alert) {
try? AVAudioSession
.sharedInstance()
.setCategory(.ambient, mode: .default, options: .mixWithOthers)
AudioServicesPlaySystemSound(alert.rawValue)
}
static func shake(_ haptic: Haptic) {
try? AVAudioSession
.sharedInstance()
.setCategory(.ambient, mode: .default, options: .mixWithOthers)
AudioServicesPlaySystemSound(haptic.rawValue)
}
}