mirror of
https://github.com/EmergeTools/Pow.git
synced 2026-03-25 08:55:50 +00:00
Extract to private method
This commit is contained in:
parent
15ddb03e22
commit
9b5a878763
1 changed files with 8 additions and 2 deletions
|
|
@ -6,14 +6,20 @@ import CoreHaptics
|
|||
internal struct Haptics {
|
||||
private static var engine: CHHapticEngine? = {
|
||||
let engine = try? CHHapticEngine()
|
||||
addHapticEngineObservers()
|
||||
return engine
|
||||
}()
|
||||
|
||||
private static func addHapticEngineObservers() {
|
||||
// Without stopping the CHHapticEngine when entering background mode, haptics are not played when the app enters the foreground.
|
||||
// See https://github.com/EmergeTools/Pow/issues/69
|
||||
NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in
|
||||
engine?.stop()
|
||||
}
|
||||
NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: nil) { _ in
|
||||
try? engine?.start()
|
||||
}
|
||||
return engine
|
||||
}()
|
||||
}
|
||||
|
||||
private static var supportsHaptics = CHHapticEngine.capabilitiesForHardware().supportsHaptics
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue