@@ -53,6 +53,7 @@ class AppController {
53
53
dispatchAction: self . handleAction
54
54
)
55
55
} ( )
56
+ private var lastHapticFeedback = Date ( timeIntervalSince1970: 0 )
56
57
57
58
init ( ) {
58
59
do {
@@ -166,21 +167,11 @@ class AppController {
166
167
167
168
case let . showErrorMessage( message) :
168
169
SVProgressHUD . showError ( withStatus: message)
169
-
170
- // Provide haptic feedback
171
- if #available( iOS 10 . 0 , * ) {
172
- let feedbackGenerator = UINotificationFeedbackGenerator ( )
173
- feedbackGenerator. notificationOccurred ( . error)
174
- }
170
+ generateFeedback ( for: . error)
175
171
176
172
case let . showSuccessMessage( message) :
177
173
SVProgressHUD . showSuccess ( withStatus: message)
178
-
179
- // Provide haptic feedback
180
- if #available( iOS 10 . 0 , * ) {
181
- let feedbackGenerator = UINotificationFeedbackGenerator ( )
182
- feedbackGenerator. notificationOccurred ( . success)
183
- }
174
+ generateFeedback ( for: . success)
184
175
185
176
case . showApplicationSettings:
186
177
guard let applicationSettingsURL = URL ( string: UIApplicationOpenSettingsURLString) else {
@@ -208,6 +199,18 @@ class AppController {
208
199
return topViewController ( presentedFrom: presentedViewController)
209
200
}
210
201
202
+ // Provide haptic feedback to accompany success and error messages
203
+ private func generateFeedback( for notificationFeedbackType: UINotificationFeedbackType ) {
204
+ if #available( iOS 10 . 0 , * ) {
205
+ let now = Date ( )
206
+ if now. timeIntervalSince ( lastHapticFeedback) > 1 {
207
+ lastHapticFeedback = now
208
+ let feedbackGenerator = UINotificationFeedbackGenerator ( )
209
+ feedbackGenerator. notificationOccurred ( notificationFeedbackType)
210
+ }
211
+ }
212
+ }
213
+
211
214
// MARK: - Public
212
215
213
216
var rootViewController : UIViewController {
0 commit comments