-
Notifications
You must be signed in to change notification settings - Fork 623
/
Copy pathVibration.m
96 lines (93 loc) · 3.78 KB
/
Vibration.m
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#import "Vibration.h"
#import <AudioToolbox/AudioToolbox.h> // Needed for AudioServicesPlaySystemSound
@implementation Vibration
+ (void)vibrateWithType:(VibrationType)type {
switch (type) {
case VibrationTypeError: {
if (@available(iOS 10.0, *)) {
UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];
[generator notificationOccurred:UINotificationFeedbackTypeError];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeSuccess: {
if (@available(iOS 10.0, *)) {
UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];
[generator notificationOccurred:UINotificationFeedbackTypeSuccess];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeWarning: {
if (@available(iOS 10.0, *)) {
UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];
[generator notificationOccurred:UINotificationFeedbackTypeWarning];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeLight: {
if (@available(iOS 10.0, *)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
[generator impactOccurred];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeMedium: {
if (@available(iOS 10.0, *)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
[generator impactOccurred];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeHeavy: {
if (@available(iOS 10.0, *)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
[generator impactOccurred];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeSoft: {
if (@available(iOS 13.0, *)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleSoft];
[generator impactOccurred];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeRigid: {
if (@available(iOS 13.0, *)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleRigid];
[generator impactOccurred];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeSelection: {
if (@available(iOS 10.0, *)) {
UISelectionFeedbackGenerator *generator = [[UISelectionFeedbackGenerator alloc] init];
[generator selectionChanged];
} else {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
break;
}
case VibrationTypeOldSchool: {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
break;
}
}
}
@end