CipherBitCorp / VolumeButtonHandler

VolumeButtonHandler for iOS
Apache License 2.0
14 stars 2 forks source link

VolumeButtonHandler

VolumeButtonHandler for iOS

A simple library inspired by https://github.com/jpsim/JPSVolumeButtonHandler but written in Swift instead.

This library handles the users up/down volume button presses.

Simply do this:

@State private var volumeHandler = VolumeButtonHandler()
volumeHandler.startHandler(disableSystemVolumeHandler: false)

volumeHandler.upBlock = {
    viewModel.volume = volumeHandler.currentVolume
    debugPrint("Up block")
}
volumeHandler.downBlock = {
    viewModel.volume = volumeHandler.currentVolume
    debugPrint("Down block")
}

Also don't forget to do volumeHandler.stopHandler() after you're done using it.

Happy coding!