River Jiang
2020-10-27 1f5eda1c9d22a3676298751c7282a5874f13bed0
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// This iOS haptic interface is a pretty straightforward implementation of UIKit's framework :
// You can learn more about these methods at https://developer.apple.com/documentation/uikit/animation_and_haptics
// DO NOT remove this from your project, or iOS vibrations won't work anymore!
 
#import <Foundation/Foundation.h>
 
UISelectionFeedbackGenerator* SelectionFeedbackGenerator;
UINotificationFeedbackGenerator* NotificationFeedbackGenerator;
UIImpactFeedbackGenerator* LightImpactFeedbackGenerator;
UIImpactFeedbackGenerator* MediumImpactFeedbackGenerator;
UIImpactFeedbackGenerator* HeavyImpactFeedbackGenerator;
UIImpactFeedbackGenerator* RigidImpactFeedbackGenerator;
UIImpactFeedbackGenerator* SoftImpactFeedbackGenerator;
 
// INIT METHOD ---------------------------------------------------------------------------
 
void MMNViOS_InstantiateFeedbackGenerators()
{
    SelectionFeedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
    NotificationFeedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
    LightImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
    MediumImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
    HeavyImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleHeavy];
    if (@available(iOS 13, *))
    {
      RigidImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleRigid];
        SoftImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleSoft];
    }
    else
    {
      RigidImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleHeavy];
        SoftImpactFeedbackGenerator =  [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];
    }
}
 
// RELEASE METHOD ---------------------------------------------------------------------------
 
void MMNViOS_ReleaseFeedbackGenerators ()
{
    SelectionFeedbackGenerator = nil;
    NotificationFeedbackGenerator = nil;
    LightImpactFeedbackGenerator = nil;
    MediumImpactFeedbackGenerator = nil;
    HeavyImpactFeedbackGenerator = nil;
    RigidImpactFeedbackGenerator = nil;
    SoftImpactFeedbackGenerator = nil;
}
 
// PREPARATION METHODS ----------------------------------------------------------------------
 
void MMNViOS_PrepareSelectionFeedbackGenerator()
{
    [SelectionFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareNotificationFeedbackGenerator()
{
    [NotificationFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareLightImpactFeedbackGenerator()
{
    [LightImpactFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareMediumImpactFeedbackGenerator()
{
    [MediumImpactFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareHeavyImpactFeedbackGenerator()
{
    [HeavyImpactFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareRigidImpactFeedbackGenerator()
{
    [RigidImpactFeedbackGenerator prepare];
}
 
void MMNViOS_PrepareSoftImpactFeedbackGenerator()
{
    [SoftImpactFeedbackGenerator prepare];
}
 
// FEEDBACK TRIGGER METHODS -------------------------------------------------------------------------
 
void MMNViOS_SelectionHaptic()
{
    [SelectionFeedbackGenerator prepare];
    [SelectionFeedbackGenerator selectionChanged];
}
 
void MMNViOS_SuccessHaptic()
{
    [NotificationFeedbackGenerator prepare];
    [NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
}
 
void MMNViOS_WarningHaptic()
{
    [NotificationFeedbackGenerator prepare];
    [NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeWarning];
}
 
void MMNViOS_FailureHaptic()
{
    [NotificationFeedbackGenerator prepare];
    [NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeError];
}
 
void MMNViOS_LightImpactHaptic()
{
    [LightImpactFeedbackGenerator prepare];
    [LightImpactFeedbackGenerator impactOccurred];
}
 
void MMNViOS_MediumImpactHaptic()
{
    [MediumImpactFeedbackGenerator prepare];
    [MediumImpactFeedbackGenerator impactOccurred];
}
 
void MMNViOS_HeavyImpactHaptic()
{
    [HeavyImpactFeedbackGenerator prepare];
    [HeavyImpactFeedbackGenerator impactOccurred];
}
 
void MMNViOS_RigidImpactHaptic()
{
    [RigidImpactFeedbackGenerator prepare];
    [RigidImpactFeedbackGenerator impactOccurred];
}
 
void MMNViOS_SoftImpactHaptic()
{
    [SoftImpactFeedbackGenerator prepare];
    [SoftImpactFeedbackGenerator impactOccurred];
}