File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Sources/Pow/Infrastructure Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,21 @@ import CoreHaptics
5
5
6
6
internal struct Haptics {
7
7
private static var engine : CHHapticEngine ? = {
8
- return try ? CHHapticEngine ( )
8
+ let engine = try ? CHHapticEngine ( )
9
+ addHapticEngineObservers ( )
10
+ return engine
9
11
} ( )
12
+
13
+ private static func addHapticEngineObservers( ) {
14
+ // Without stopping the CHHapticEngine when entering background mode, haptics are not played when the app enters the foreground.
15
+ // See https://github.com/EmergeTools/Pow/issues/69
16
+ NotificationCenter . default. addObserver ( forName: UIApplication . didEnterBackgroundNotification, object: nil , queue: nil ) { _ in
17
+ engine? . stop ( )
18
+ }
19
+ NotificationCenter . default. addObserver ( forName: UIApplication . willEnterForegroundNotification, object: nil , queue: nil ) { _ in
20
+ try ? engine? . start ( )
21
+ }
22
+ }
10
23
11
24
private static var supportsHaptics = CHHapticEngine . capabilitiesForHardware ( ) . supportsHaptics
12
25
You can’t perform that action at this time.
0 commit comments